Node.js utility to execute a sequence of asynchronous functions without getting into callback hell.
It has the good parts of async.waterfall and step put together !
- catches error thrown out by a step
- keeps 'next' as explicit argument (not using
this
) - receives an explicit error callback (no more
if (err) return callback(err)
in every step) - halts the execution of remaining steps on error
npm install node-flow
var flow = require('node-flow');
function getThisDone(callback) {
flow(callback,
function one(next) {
console.log('step one');
next(null, 'cool');
},
function two(next, msg) {
console.log('step two: ', msg);
next();
},
function three(next) {
console.log('step three');
next(null, 'wow');
}
);
}
getThisDone(function(err, result) {
if (err) {
console.log('oops! ', err);
} else {
console.log('result: ', result);
}
});
check out Co if you're running node.js with generator support