Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Waterfall with {} input #195

Closed
abrkn opened this Issue Oct 31, 2012 · 8 comments

Comments

Projects
None yet
4 participants

abrkn commented Oct 31, 2012

No description provided.

Contributor

brianmaissy commented Feb 20, 2013

@abrkn could you clarify the issue/request?

I may be able to elaborate on this request since I think I just ran into it.

async.waterfall() works when you pass in an array of functions, but does not work if you pass in an object of named functions. async will just immediately invoke the final callback, without calling any of the tasks.

example:
This works as expected:

async.waterfall([
function() {...},
function(){...}
],
function(err, results){
})

This does nothing but call the final function:

async.waterfall({
f1: function() {...},
f2: function(){...}
},
function(err, results){
})

In the 2nd, nonworking example, if you change waterfall to series, it works as expected.

Contributor

brianmaissy commented Feb 21, 2013

I don't think this is possible, since the order of the functions needs to be well-defined in waterfall, and an object's attributes aren't ordered. See also #187

That makes sense! The waterfall() function should probably check the input parameters to catch this error then.

Contributor

brianmaissy commented Feb 22, 2013

What do you mean by catch the error? When it calls the callback it should provide an error instead of failing silently? That makes sense to me. @caolan, thoughts?

Yes, through an assertion, exception, or through the error parameter into the callback, it would be nice to alert the programmer that he is using the function in an unsupported way, especially since that 'unsupported way' is consistent with other functions in the library.

Contributor

brianmaissy commented Feb 24, 2013

I definitely think it should be through the error parameter, not by throwing an exception, but I agree with you. If @caolan likes this, I'll submit a pull request. Something along the lines of

if (tasks.constructor !== Array) {
  var err = new Error('First argument to waterfall must be an array of functions');
  callback(err);
}else ...
Owner

caolan commented Mar 2, 2013

@brianmaissy yep, looks good to me. A pull request with a test would be much appreciated.

@caolan caolan closed this Mar 28, 2014

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