Skip to content

Commit

Permalink
Merge pull request #827 from megawac/create-apply-each
Browse files Browse the repository at this point in the history
Optimize applyEach* via creator function
  • Loading branch information
aearly committed Jul 2, 2015
2 parents 69a3b67 + 0f8d920 commit ac170ba
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -1147,29 +1147,27 @@
};


var _applyEach = _restParam(function _applyEach(eachfn, fns, args) {
var go = _restParam(function(args) {
var that = this;
var callback = args.pop();
return eachfn(fns, function (fn, _, cb) {
fn.apply(that, args.concat([cb]));
},
callback);
function _applyEach(eachfn) {
return _restParam(function(fns, args) {
var go = _restParam(function(args) {
var that = this;
var callback = args.pop();
return eachfn(fns, function (fn, _, cb) {
fn.apply(that, args.concat([cb]));
},
callback);
});
if (args.length) {
return go.apply(this, args);
}
else {
return go;
}
});
if (args.length) {
return go.apply(this, args);
}
else {
return go;
}
});
}

async.applyEach = _restParam(function (args) {
return _applyEach.apply(null, [async.eachOf].concat(args));
});
async.applyEachSeries = _restParam(function (args) {
return _applyEach.apply(null, [async.eachOfSeries].concat(args));
});
async.applyEach = _applyEach(async.eachOf);
async.applyEachSeries = _applyEach(async.eachOfSeries);


async.forever = function (fn, callback) {
Expand Down

0 comments on commit ac170ba

Please sign in to comment.