waterfall should pass data from all tasks #143

ghost opened this Issue Jun 24, 2012 · 0 comments


None yet
1 participant

ghost commented Jun 24, 2012

I have a sequence where the 3rd task needs data from the 1st one. Also the error/end callback needs the data from the 1st one.

I think waterfall should pass data from all the above tasks so the ones below can access it.

Perhaps the first argument passed to each task should be an aggregated result array eg.

        callback(null, 'one', 'two');
    function(results, arg1, arg2, callback){
        // results[0][0] = 'one'
        // results[0][1] = 'two'
        callback(null, 'three');
    function(results, arg1, callback){
        // results[0][0] = 'one'
        // results[0][1] = 'two'
        // results[1][0] = 'three'
        // arg1 now equals 'three'
        callback(null, 'done');
], function (err, results, result) {
    // results[0][0] = 'one'
    // results[0][1] = 'two'
    // results[1][0] = 'three'
    // results[2][0] = 'done'
   // result now equals 'done'    

And if an object is passed to waterfall, then the results would be an object instead as usual.

So far I have declared some variables outside of waterfall and assigned values to those I wanna use below. But that leads to code smell. I would rather have a specific async flow pattern for this use case.

And if waterfall can't be changed we could perhaps have another async helper for it? Good for backwards compatibility but also for performance when you don't need this kind of functionality.

What do you think?

caolan closed this Mar 28, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment