Node.js module for execute a sequencing a number of dependent functions and return a promise when the operation is done
npm install promise-pipeline
This is the generic way to initialize a Pipeline object
var Pipeline = require('promise-pipeline')
var pipeline = new Pipeline()
.use(func1)
.use(func2)
.use(function(input, output, next) {
console.log(output)
next()
})
var input = {
data: 'some initial value'
}
var output = {}
pipeline.start(input, output)
.then(o => {
//Do something whit the final output
})
Each function of the pipeline receives 3 parameters: input, output, next
function func1(input, output, next){
output.data = input.data
//Do something great here, next call the next function
next()
}
function func2(input, output, next){
db.insert(output).then(o => {
next()
})
}