Pass arguments to the first function in waterfall? #14

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

Comments

Projects
None yet
8 participants
@ghost

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

This comment has been minimized.

Show comment Hide comment
@c2c533c4f237

c2c533c4f237 Mar 3, 2011

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

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

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

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Mar 3, 2011

Great hack =)

ghost commented Mar 3, 2011

Great hack =)

@ghost

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Aug 17, 2014

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

ghost commented Aug 17, 2014

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

@adisos

This comment has been minimized.

Show comment Hide comment
@adisos

adisos Nov 19, 2014

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

});

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

adisos commented Nov 19, 2014

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

});

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

This comment has been minimized.

Show comment Hide comment
@sgarbesi

sgarbesi Dec 14, 2014

@adisos thanks! +1

@adisos thanks! +1

@marcolino

This comment has been minimized.

Show comment Hide comment
@marcolino

marcolino Dec 6, 2015

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... :-/

Contributor

marcolino commented Dec 6, 2015

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

This comment has been minimized.

Show comment Hide comment
@megawac

megawac Dec 6, 2015

Collaborator

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

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

This comment has been minimized.

Show comment Hide comment
@jingles

jingles Dec 21, 2015

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

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

This comment has been minimized.

Show comment Hide comment
@ssrballin

ssrballin Sep 18, 2016

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

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