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

constant() should support dynamic args #1016

Closed
ross-nordstrom opened this issue Jan 28, 2016 · 2 comments
Closed

constant() should support dynamic args #1016

ross-nordstrom opened this issue Jan 28, 2016 · 2 comments
Milestone

Comments

@ross-nordstrom
Copy link

In v1.5.2 constant seems to be hard-coded to be invoked with 1 arg: a callback. This is limiting

    async.constant = _restParam(function(values) {
        var args = [null].concat(values);
        return function (callback) {
            return callback.apply(this, args);
        };
    });

I'd like to propose the inner, curried function take dynamic args as well:

    async.constant = _restParam(function(values) {
        var args = [null].concat(values);
        return _restParam(function (callbackArgs) { // <= We only care about the callback,
            var callback = callbackArgs.pop();      //    and assume it's the last arg
            return callback.apply(this, args);      //    when the curried function is invoked
        });
    });

Why do I care?

Composability. I don't want to care about the callback-signature of other functions in Async-chains.

async.waterfall([
  doSomething/*(cb)*/, //=> Invokes cb with (err, arg1, arg2)
  async.constant('Pretend doSomething did somethingElse')/*(arg1, arg2, cb)*/
], doneCb);
@aearly aearly added the feature label Feb 2, 2016
@aearly
Copy link
Collaborator

aearly commented Feb 2, 2016

I like this -- a simple enhancement.

@aearly aearly added enhancement and removed feature labels Feb 9, 2016
ajfranzoia added a commit to ajfranzoia/async that referenced this issue Mar 8, 2016
aearly added a commit that referenced this issue Mar 8, 2016
Support dynamic arguments in async.constant (ref. #1016)
@aearly aearly added this to the 2.0 milestone Mar 8, 2016
@aearly
Copy link
Collaborator

aearly commented Mar 8, 2016

Closed via #1052

@aearly aearly closed this as completed Mar 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants