diff --git a/lib/internal/eachOfLimit.js b/lib/internal/eachOfLimit.js index ae153b1a2..2928366dc 100644 --- a/lib/internal/eachOfLimit.js +++ b/lib/internal/eachOfLimit.js @@ -9,7 +9,10 @@ import breakLoop from './breakLoop'; export default function _eachOfLimit(limit) { return function (obj, iteratee, callback) { callback = once(callback || noop); - if (limit <= 0 || !obj) { + if (limit <= 0) { + throw new RangeError('concurrency limit cannot be less than 1') + } + if (!obj) { return callback(null); } var nextElem = iterator(obj); diff --git a/lib/internal/queue.js b/lib/internal/queue.js index 575497b18..a421d2e29 100644 --- a/lib/internal/queue.js +++ b/lib/internal/queue.js @@ -9,7 +9,7 @@ export default function queue(worker, concurrency, payload) { concurrency = 1; } else if(concurrency === 0) { - throw new Error('Concurrency must not be zero'); + throw new RangeError('Concurrency must not be zero'); } var _worker = wrapAsync(worker); diff --git a/test/concat.js b/test/concat.js index f6b73b3b9..75f8db7e9 100644 --- a/test/concat.js +++ b/test/concat.js @@ -293,15 +293,15 @@ describe('concat', function() { }); }); - it('zero limit', function(done) { - async.concatLimit([3, 2, 2, 1], 0, function(val, next) { - assert(false, 'iteratee should not be called'); - next(); - }, function(err, result) { - expect(err).to.eql(null); - expect(result).to.be.an('array').that.is.empty; - done(); - }); + it('zero limit', function() { + expect(() => { + async.concatLimit([3, 2, 2, 1], 0, function(val, next) { + assert(false, 'iteratee should not be called'); + next(); + }, function() { + assert(false, 'callback should not be called'); + }); + }).to.throw(/limit/) }); it('does not continue replenishing after error', function(done) { diff --git a/test/each.js b/test/each.js index 014e9df99..ba5f3c4a1 100644 --- a/test/each.js +++ b/test/each.js @@ -199,15 +199,15 @@ describe("each", function() { }); }); - it('eachLimit zero limit', function(done) { - async.eachLimit([0,1,2,3,4,5], 0, function(x, callback){ - assert(false, 'iteratee should not be called'); - callback(); - }, function(err){ - if (err) throw err; - assert(true, 'should call callback'); - }); - setTimeout(done, 25); + it('eachLimit zero limit', function() { + expect(() => { + async.eachLimit([0,1,2,3,4,5], 0, function(x, callback){ + assert(false, 'iteratee should not be called'); + callback(); + }, function(){ + assert(false, 'should not call callback'); + }); + }).to.throw(/limit/) }); it('eachLimit error', function(done) { diff --git a/test/eachOf.js b/test/eachOf.js index 7d80990c4..1701d3ed0 100644 --- a/test/eachOf.js +++ b/test/eachOf.js @@ -299,15 +299,15 @@ describe("eachOf", function() { }); }); - it('forEachOfLimit zero limit', function(done) { - async.forEachOfLimit({ a: 1, b: 2 }, 0, function(x, callback){ - assert(false, 'iteratee should not be called'); - callback(); - }, function(err){ - if (err) throw err; - assert(true, 'should call callback'); - }); - setTimeout(done, 25); + it('forEachOfLimit zero limit', function() { + expect(() => { + async.forEachOfLimit({ a: 1, b: 2 }, 0, function(x, callback){ + assert(false, 'iteratee should not be called'); + callback(); + }, function(){ + assert(true, 'should call callback'); + }); + }).to.throw(/concurrency limit/) }); it('forEachOfLimit no limit', function(done) { diff --git a/test/groupBy.js b/test/groupBy.js index d20f385f4..796d353db 100644 --- a/test/groupBy.js +++ b/test/groupBy.js @@ -247,15 +247,15 @@ describe('groupBy', function() { }); }); - it('zero limit', function(done) { - async.groupByLimit([3, 2, 2, 1], 0, function(val, next) { - assert(false, 'iteratee should not be called'); - next(); - }, function(err, result) { - expect(err).to.eql(null); - expect(result).to.eql({}); - done(); - }); + it('zero limit', function() { + expect(() => { + async.groupByLimit([3, 2, 2, 1], 0, function(val, next) { + assert(false, 'iteratee should not be called'); + next(); + }, function() { + assert(false, 'should not be called'); + }); + }).to.throw(/concurrency limit/) }); it('does not continue replenishing after error', function(done) { diff --git a/test/map.js b/test/map.js index c7f503021..eb0c3eacd 100644 --- a/test/map.js +++ b/test/map.js @@ -224,15 +224,15 @@ describe("map", function() { }); }); - it('mapLimit zero limit', function(done) { - async.mapLimit([0, 1, 2, 3, 4, 5], 0, function(x, callback) { - assert(false, 'iteratee should not be called'); - callback(); - }, function(err, results) { - expect(results).to.eql([]); - assert(true, 'should call callback'); - }); - setTimeout(done, 25); + it('mapLimit zero limit', function() { + expect(() => { + async.mapLimit([0, 1, 2, 3, 4, 5], 0, function(x, callback) { + assert(false, 'iteratee should not be called'); + callback(); + }, function() { + assert(false, 'should not be called'); + }); + }).to.throw(/concurrency limit/) }); it('mapLimit error', function(done) {