-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
Milestone
Description
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);