From 61b0bc97e461f923b091e8d0c87f92e308d73eda Mon Sep 17 00:00:00 2001 From: Alexander Early Date: Sun, 1 Jul 2018 17:24:43 -0700 Subject: [PATCH 1/2] BREAKING CHANGE: limits of less than 1 are now an error --- lib/internal/eachOfLimit.js | 5 ++++- lib/internal/queue.js | 2 +- test/concat.js | 18 +++++++++--------- test/each.js | 18 +++++++++--------- test/eachOf.js | 18 +++++++++--------- test/groupBy.js | 18 +++++++++--------- test/map.js | 18 +++++++++--------- 7 files changed, 50 insertions(+), 47 deletions(-) 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..e8f1fcf68 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(err, result) { + 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..dcc79a0ed 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(err){ + 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..f6b9ad5ab 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(err){ + 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..6199aa9b5 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(err, result) { + 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..8881e032e 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(err, results) { + assert(false, 'should not be called'); + }); + }).to.throw(/concurrency limit/) }); it('mapLimit error', function(done) { From 6d359e8dce2256ee44fb293a63df412fc55e815b Mon Sep 17 00:00:00 2001 From: Alexander Early Date: Sun, 1 Jul 2018 17:30:30 -0700 Subject: [PATCH 2/2] fix lint --- test/concat.js | 2 +- test/each.js | 2 +- test/eachOf.js | 2 +- test/groupBy.js | 2 +- test/map.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/concat.js b/test/concat.js index e8f1fcf68..75f8db7e9 100644 --- a/test/concat.js +++ b/test/concat.js @@ -298,7 +298,7 @@ describe('concat', function() { async.concatLimit([3, 2, 2, 1], 0, function(val, next) { assert(false, 'iteratee should not be called'); next(); - }, function(err, result) { + }, function() { assert(false, 'callback should not be called'); }); }).to.throw(/limit/) diff --git a/test/each.js b/test/each.js index dcc79a0ed..ba5f3c4a1 100644 --- a/test/each.js +++ b/test/each.js @@ -204,7 +204,7 @@ describe("each", function() { async.eachLimit([0,1,2,3,4,5], 0, function(x, callback){ assert(false, 'iteratee should not be called'); callback(); - }, function(err){ + }, function(){ assert(false, 'should not call callback'); }); }).to.throw(/limit/) diff --git a/test/eachOf.js b/test/eachOf.js index f6b9ad5ab..1701d3ed0 100644 --- a/test/eachOf.js +++ b/test/eachOf.js @@ -304,7 +304,7 @@ describe("eachOf", function() { async.forEachOfLimit({ a: 1, b: 2 }, 0, function(x, callback){ assert(false, 'iteratee should not be called'); callback(); - }, function(err){ + }, function(){ assert(true, 'should call callback'); }); }).to.throw(/concurrency limit/) diff --git a/test/groupBy.js b/test/groupBy.js index 6199aa9b5..796d353db 100644 --- a/test/groupBy.js +++ b/test/groupBy.js @@ -252,7 +252,7 @@ describe('groupBy', function() { async.groupByLimit([3, 2, 2, 1], 0, function(val, next) { assert(false, 'iteratee should not be called'); next(); - }, function(err, result) { + }, function() { assert(false, 'should not be called'); }); }).to.throw(/concurrency limit/) diff --git a/test/map.js b/test/map.js index 8881e032e..eb0c3eacd 100644 --- a/test/map.js +++ b/test/map.js @@ -229,7 +229,7 @@ describe("map", function() { async.mapLimit([0, 1, 2, 3, 4, 5], 0, function(x, callback) { assert(false, 'iteratee should not be called'); callback(); - }, function(err, results) { + }, function() { assert(false, 'should not be called'); }); }).to.throw(/concurrency limit/)