Skip to content

Commit

Permalink
limits of less than 1 are now an error (#1552)
Browse files Browse the repository at this point in the history
* BREAKING CHANGE: limits of less than 1 are now an error

* fix lint
  • Loading branch information
aearly committed Jul 2, 2018
1 parent 53f6130 commit 6405b10
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 47 deletions.
5 changes: 4 additions & 1 deletion lib/internal/eachOfLimit.js
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/queue.js
Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions test/concat.js
Expand Up @@ -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) {
Expand Down
18 changes: 9 additions & 9 deletions test/each.js
Expand Up @@ -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) {
Expand Down
18 changes: 9 additions & 9 deletions test/eachOf.js
Expand Up @@ -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) {
Expand Down
18 changes: 9 additions & 9 deletions test/groupBy.js
Expand Up @@ -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) {
Expand Down
18 changes: 9 additions & 9 deletions test/map.js
Expand Up @@ -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) {
Expand Down

0 comments on commit 6405b10

Please sign in to comment.