@defiantcaptain/spork-js
TypeScript icon, indicating that this package has built-in type declarations

1.1.4 • Public • Published

#Spork-JS

Not designed for external conusmption as its usage won't make much sense.

 Spork.$('main.js').fork(1, (it) => {
     return ["bob"];
 }).join((results) => {
     process.send({event: 'done', results: results});
 }).error((err) => {
     console.log(err);
 }).start();

$('main.js') is the script to be executed, with Spork Spork::fork(n, callback) representing the number of main.js arguments to execute, and the callback designed to provide string[] as arguments to the program. join is called when all forked processes are completed, and the error is designed to provide details about the failure. start finalizes the process and beings the forking process formally.

start must always be invoked last, but fork, join and error can be added to the Spork in any order.

Objects and Whatnot

IDisposable

Interface to prevent objects from being reused. A Spork is intended to be used once only.

Spork implements IDisposable

Class that implements the forking logic.

  • static $(script : string) takes a string that is the script to be executed.
  • get eventID() : string is a uuidv1 of the Spork for mapping purposes.
  • isDisposed() : boolean is true if the object has been disposed. The object disposes itself.
  • join ((...) => void) is invoked when all forks are done.
  • error((...) => void) is invoked if there is a detected and expected error.
  • fork(n:number, (iteration) => string[]) is the forking operation that takes a number of iterations n and a closer that is invoked on each iteration to great a list of strings that serve as arguments.
  • start() to begin the forking process.
  • result(instanceID : string, value : any) is a callback to be invoked when a particular forked event has a result; each forked process as an instanceID for the fork.

All public facing functions, if invoked on a disposed object, will throw an error string this is dead. This object is not designed for reuse.

###Events SporkEvents.JOIN dispatched when all forks are done. SporkEvents.ERROR dispatched when an error happens. SporkProcessEvents.FORK_ME dispatched when we ask the governing application for forks. SporkProcessEvents.DONE is dispatched when a spawned process is complete.

###SporkHandler Namespace Contains a mapping object SporkMap that is a hash of outlying events. This is global, and each individual Spork deals with specific instances.

Readme

Keywords

none

Package Sidebar

Install

npm i @defiantcaptain/spork-js

Weekly Downloads

0

Version

1.1.4

License

MIT

Last publish

Collaborators

  • defiantcaptain