Skip to content

Instantly share code, notes, and snippets.

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 manishkpr/7dcbe1e37c7cb22975d1054d891147e4 to your computer and use it in GitHub Desktop.
Save manishkpr/7dcbe1e37c7cb22975d1054d891147e4 to your computer and use it in GitHub Desktop.
NodeJS Async WaterFall Example
var async = require('async');
async.waterfall(
[
function(callback) {
callback(null, 'Yes', 'it');
},
function(arg1, arg2, callback) {
var caption = arg1 +' and '+ arg2;
callback(null, caption);
},
function(caption, callback) {
caption += ' works!';
callback(null, caption);
}
],
function (err, caption) {
console.log(caption);
// Node.js and JavaScript Rock!
}
);
//## Another Way
var secondCallBack = function(arg1, arg2) {
var caption = arg1 +' and '+ arg2;
thirdCallBack(caption);
}
var thirdCallBack = function(caption) {
caption += ' works!';
finalCallBack(null, caption);
}
var finalCallBack = function (err, caption) {
console.log(caption);
// Node.js and JavaScript Rock!
}
async.waterfall(
[
function(callback) {
secondCallBack('Yes', 'it');
},
secondCallBack
,
thirdCallBack
],
finalCallBack
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment