I'm taking a look at the async library but I can't seem to find a control flow for handling pipelines. I'm just wondering if I'm missing something here.
I want to implement a pipeline. Example:
let pipeline = [];
pipeline.push((input, next) => { next(null, input); });
pipeline.push((input, next) => { next(null, input); });
var pipelineResult = pipelineRunner.run(pipeline, 'sample input', (error, result) => {});
Explanation: A series of functions is called. Each function receives an input
and a next
function. Each function processes the input
and passes it as a parameter to the next
function. As a result of the pipeline execution, I get the processed input
, or, if any function calls next
with an error, the pipeline stops and the callback is called.
I guess this is a pretty common use case so I think async can do it, but I'm not being able to find it. If you know of any other library that can achieve such result, that would be acceptable too.
You are looking for the async.waterfall
function.
Alternatively you can apply asyc.seq
or async.compose
with multiple arguments if you need a function that you can pass an initial input
to.