-
-
Save brycebaril/4577164 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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