Navigation Menu

Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass arguments to the first function in waterfall? #14

Closed
ghost opened this issue Feb 25, 2011 · 9 comments
Closed

Pass arguments to the first function in waterfall? #14

ghost opened this issue Feb 25, 2011 · 9 comments

Comments

@ghost
Copy link

ghost commented Feb 25, 2011

It doesn't seem to be possible to pass arguments to the first function in waterfall.

Could this be done in other ways because I really need the first one to get some variables.

@c2c533c4f237
Copy link

Define a dummy function that calls your function with the variables you need. LIke this:
async.waterfall([

function(cb)
{
  cb(null, username, password);
},
Authenticate,...

@ghost
Copy link
Author

ghost commented Mar 3, 2011

Great hack =)

@ghost
Copy link
Author

ghost commented Aug 17, 2014

An alternative is to use async.apply(authenticate, username, password) to bind the arguments up front.

@adis-io
Copy link

adis-io commented Nov 19, 2014

async.waterfall([
    async.apply(func1, "1")
], function (err, result) {

});

function func1(par1, callback) {
    console.log(par1); // Outputs: 1
}

@sgarbesi
Copy link

@adisos thanks! +1

@marcolino
Copy link
Contributor

Hmmm... Great hacks, really... I too was puzzled by not being able to pass parameters to first waterfall function... But, shouldn't this be post to module author (caolan) as a bug/inconsistency ? All the neatness of that method vanishes, with these hacks... :-/

@megawac
Copy link
Collaborator

megawac commented Dec 6, 2015

This is the intended use of these methods. async.apply was added mainly for this use case AFAIK

The documentation does give examples of using waterfall with a function, however, if anyone wants to amend the readme to show using waterfall with apply that would be fantastic

@jingles
Copy link

jingles commented Dec 21, 2015

👍 @adisos apply is great! i've only been using this library a little while and I am continually impressed.

@ssrballin
Copy link

if anyone still has this issue, the constant function works very well.

async.waterfall([
    async.constant(42),
    function (value, next) {
        // value === 42
    },
], callback);

For more info, check out http://caolan.github.io/async/docs.html#.constant

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants