Skip to content

Instantly share code, notes, and snippets.

@brycebaril
Forked from cxreg/gist:4577093
Last active December 11, 2015 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brycebaril/4577164 to your computer and use it in GitHub Desktop.
Save brycebaril/4577164 to your computer and use it in GitHub Desktop.
var async = require('async');
function one(cb) {
console.log("running one");
cb(null, function () { return "one" });
}
function two(cb) {
console.log("running two");
function three(callback){
console.log("running three");
var a = [];
for (var i = 1; i <= 3; i++) {
a.push(i);
};
callback(null, function () { return "three"}, a);
}
function four(last, a, callback) {
console.log("running four");
console.log(a);
callback(null, [last, function () { return "four"}]);
}
async.waterfall([three, four], cb);
}
function five(cb) {
console.log("running five");
cb(null, function () { return "five" });
}
function output(error, results) {
// if (error) ...
var flat = [];
results.forEach(function (r) {
flat = flat.concat(r);
});
flat.forEach(function (fn) {
console.log(fn());
});
}
async.series([one, two, five], output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment