Skip to content

Commit

Permalink
have applyEach pass results to the callback. Closes #1088
Browse files Browse the repository at this point in the history
  • Loading branch information
aearly committed Apr 7, 2016
1 parent 167a019 commit b00abf2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/applyEach.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import applyEach from './internal/applyEach';
import eachOf from './eachOf';
import map from './map';

export default applyEach(eachOf);
export default applyEach(map);
4 changes: 2 additions & 2 deletions lib/applyEachSeries.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import applyEach from './internal/applyEach';
import eachOfSeries from './eachOfSeries';
import mapSeries from './mapSeries';

export default applyEach(eachOfSeries);
export default applyEach(mapSeries);
5 changes: 2 additions & 3 deletions lib/internal/applyEach.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ export default function applyEach(eachfn) {
return rest(function(fns, args) {
var go = initialParams(function(args, callback) {
var that = this;
return eachfn(fns, function (fn, _, cb) {
return eachfn(fns, function (fn, cb) {
fn.apply(that, args.concat([cb]));
},
callback);
}, callback);
});
if (args.length) {
return go.apply(this, args);
Expand Down
9 changes: 6 additions & 3 deletions mocha_test/applyEach.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ describe('applyEach', function () {
cb(null, 3);
}, 15);
};
async.applyEach([one, two, three], 5, function (err) {
async.applyEach([one, two, three], 5, function (err, results) {
assert(err === null, err + " passed instead of 'null'");
expect(call_order).to.eql(['two', 'one', 'three']);
expect(results).to.eql([1, 2, 3]);
done();
});
});
Expand Down Expand Up @@ -57,9 +58,10 @@ describe('applyEach', function () {
cb(null, 3);
}, 15);
};
async.applyEachSeries([one, two, three], 5, function (err) {
async.applyEachSeries([one, two, three], 5, function (err, results) {
assert(err === null, err + " passed instead of 'null'");
expect(call_order).to.eql(['one', 'two', 'three']);
expect(results).to.eql([1, 2, 3]);
done();
});
});
Expand Down Expand Up @@ -87,9 +89,10 @@ describe('applyEach', function () {
cb(null, 3);
}, 15);
};
async.applyEach([one, two, three])(5, function (err) {
async.applyEach([one, two, three])(5, function (err, results) {
if (err) throw err;
expect(call_order).to.eql(['two', 'one', 'three']);
expect(results).to.eql([1, 2, 3]);
done();
});
});
Expand Down

0 comments on commit b00abf2

Please sign in to comment.