Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limits of less than 1 are now an error #1552

Merged
merged 2 commits into from Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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