Nodejs async series – pass arguments to next callback

You can chain together asynchronous functions with the async module’s waterfall function. This allows you to say, “first do x, then pass the results to function y, and pass the results of that to z.” Copied from the [docs][1]:

async.waterfall([
    function(callback){
        callback(null, 'one', 'two');
    },
    function(arg1, arg2, callback){
        // arg1 now equals 'one' and arg2 now equals 'two'
        callback(null, 'three');
    },
    function(arg1, callback){
        // arg1 now equals 'three'
        callback(null, 'done');
    }
], function (err, result) {
   // result now equals 'done'    
});

You don’t strictly need the async module to accomplish this; this function is designed to make the code easier to read. If you don’t want to use the async module, you can always just use traditional callbacks.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)