Skip to content

Commit

Permalink
allow no callback for detect, some and family. Fixes #1096
Browse files Browse the repository at this point in the history
  • Loading branch information
aearly committed Apr 5, 2016
1 parent e9f6f75 commit ae24881
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/internal/createTester.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
import noop from 'lodash/noop';

export default function _createTester(eachfn, check, getResult) {
return function(arr, limit, iteratee, cb) {
Expand Down Expand Up @@ -27,9 +28,11 @@ export default function _createTester(eachfn, check, getResult) {
});
}
if (arguments.length > 3) {
cb = cb || noop;
eachfn(arr, limit, wrappedIteratee, done);
} else {
cb = iteratee;
cb = cb || noop;
iteratee = limit;
eachfn(arr, wrappedIteratee, done);
}
Expand Down
14 changes: 14 additions & 0 deletions mocha_test/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ describe("detect", function () {
}, 50);
});

it('detect no callback', function(done) {
var calls = [];

async.detect([1, 2, 3], function (val, cb) {
calls.push(val);
cb();
});

setTimeout(function () {
expect(calls).to.eql([1, 2, 3]);
done();
}, 10)
});

it('detectSeries - ensure stop', function (done) {
async.detectSeries([1, 2, 3, 4, 5], function (num, cb) {
if (num > 3) throw new Error("detectSeries did not stop iterating");
Expand Down
14 changes: 14 additions & 0 deletions mocha_test/some.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ describe("some", function () {
});
});

it('some no callback', function(done) {
var calls = [];

async.some([1, 2, 3], function (val, cb) {
calls.push(val);
cb();
});

setTimeout(function () {
expect(calls).to.eql([1, 2, 3]);
done();
}, 10)
});

it('someLimit true', function(done){
async.someLimit([3,1,2], 2, function(x, callback){
setTimeout(function(){callback(null, x === 2);}, 0);
Expand Down

0 comments on commit ae24881

Please sign in to comment.