Function Pipe
A function pipe eases the construction of extensible processing pipelines.
Each step in the pipeline takes the result of the prior step as input, and produces its own result, which in turn, is used by the next step in the pipeline, until processing is complete and a final result is produced. Each step in the pipeline can be thought of as middleware, but unlike the connect framework, the inputs and outputs are not related to nodejs' original callback pattern.
2018 Breaking Changes
The 2018 version 1.0.0 has very little in common with the version published in 2012. The 2018 version of the Pipe
is exclusively ES6, and is intended for use in nodejs.
Getting Started
Create a pipeline by constructing an instance of the Pipe
class, optionally specifying initial processing steps, then as needed, add additional processing steps using the .pipe()
method, and eventually, execute the pipeline using the .process()
method.
const res = await fn1 ; console;
The result of each step in the process cascades into the next step, just like Promise
's .then()
method.
arg ---v fn1(arg1) ---v fn2(arg2) ---v fn3(arg3) ---v result
The constructor can take multiple steps...
const res = await fn1 fn2 fn3; console;
.pipe()
can take multiple steps...
const res = await fn2 ;
Arguments passed to .process()
are projected into the first step...
const res = await x + y ;
Each step's result can be projected down stream in the pipe...
const res = await x * 2 y * 5 true ;
Errors propagate to the caller...
const stdout = consolelog;try const res = await ; catch err assert;