pipeworks
Create pipes. Fit 'em together. Start the flow!
With pipeworks, you can:
- Fit components into execution pipelines.
- Siphon the flow into branches during execution.
- Join multiple pipelines together.
- Intercept errors during execution.
Example
var pipeworks = ; ; // Output:// I B3T I C0U1D 34T M0R3 T0FU R011S TH4N 4NY0N3!!11~!11!
Install
$ npm install pipeworks
Usage
initialize
Start by initializing a pipeline.
var pipeworks = ; var pipeline = ;
pipes
Pipes are the modular component of pipeworks. Fit pipes together to form a pipeline.
They have the following signature: function([arguments], next)
. Pipes can take any number of arguments you wish to pass. However, it's common to use a single context
variable as a record to pass state between steps in the execution pipeline. The last parameter passed to a pipe is a reference to the next function in the pipeline. Pipes should always end with a call to next([arguments])
.
See below.
var { contextscores = 250 170 147; ;};
pipeline.fit([options], pipe)
Add a pipe to the pipeline.
options.affinity
- Either hoist
or sink
. Adds to the pre and post queues, respectively. Ensures a pipe gets fitted before or after the main execution pipeline.
The effect of setting the pipeline affinity to 'hoist'
:
; // Output:// Ricky Bobby: If you ain't first, you're last!// Cal Naughton, Jr: Shake and bake!
pipeline.siphon([arguments], next)
Redirect the flow to another pipeline.
var hijacker = ;var main = ; hijacker ; main ; main; // Output: // getting started// am i getting hijacked?// hijacked!// done-zo
pipeline.join(pipeline)
Link pipelines together.
var first = ;var second = ;var third = ; first ; second ; third ; first; // Output:// alpha// atlanta// beta// boise// gamma// georgetown
pipeline.flow([arguments])
Send something down the pipeline! Any number of arguments can be sent, but often there's just a single context
object.
; // Output:// { name: 'Kevin', age: 30 }
pipeline.fault(callback)
Handle errors during pipeline execution. Using pipeline.fault
allows access to the current execution context when errors occur in
the pipeline.
callback
- has the signaturefunction([arguments], error, next)
[arguments]
- the list of arguments sent to the currently executing pipeerror
is what was thrownnext
is a reference to the following pipe in the pipeline. Thenext
argument, in most cases, should not be called.
Note: It's advisable to exit the process after an uncaught exception. Exceptions leave your application in an unknown state. This method uses domains under the hood.
var breakfast = ; breakfast; breakfast
Usage Notes: Joined pipelines should be treated as new pipelines. Use fault on the joined pipeline itself for reliability. It is possible to have different fault handlers for each pipeline when using siphon.
Enjoy!
License
MIT