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

Fixed issue with _eachLimit continuing to run after error #754

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,20 @@
var completed = 0;
var started = 0;
var running = 0;
var errored = false;

(function replenish () {
if (completed >= arr.length) {
return callback(null);
}

while (running < limit && started < arr.length) {
while (running < limit && started < arr.length && !errored) {
started += 1;
running += 1;
iterator(arr[started - 1], function (err) {
if (err) {
callback(err);
errored = true;
callback = noop;
}
else {
Expand Down
83 changes: 83 additions & 0 deletions test/test-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,42 @@ exports['parallel call in another context'] = function(test) {
vm.runInNewContext(fn, sandbox);
};

exports['parallel does not continue replenishing after error'] = function (test) {
var started = 0;
var arr = [
funcToCall,
funcToCall,
funcToCall,
funcToCall,
funcToCall,
funcToCall,
funcToCall,
funcToCall,
funcToCall,
];
var delay = 10;
var limit = 3;
var maxTime = 10 * arr.length;
function funcToCall(callback) {
started ++;
if (started === 3) {
return callback(new Error ("Test Error"));
}
setTimeout(function(){
callback();
}, delay);
}

async.parallelLimit(arr, limit, function(x, callback) {

}, function(err){});

setTimeout(function(){
test.equal(started, 3);
test.done();
}, maxTime);
};


exports['series'] = function(test){
var call_order = [];
Expand Down Expand Up @@ -1386,6 +1422,30 @@ exports['eachLimit synchronous'] = function(test){
});
};


exports['eachLimit does not continue replenishing after error'] = function (test) {
var started = 0;
var arr = [0,1,2,3,4,5,6,7,8,9];
var delay = 10;
var limit = 3;
var maxTime = 10 * arr.length;

async.eachLimit(arr, limit, function(x, callback) {
started ++;
if (started === 3) {
return callback(new Error ("Test Error"));
}
setTimeout(function(){
callback();
}, delay);
}, function(err){});

setTimeout(function(){
test.equal(started, 3);
test.done();
}, maxTime);
};

exports['forEachSeries alias'] = function (test) {
test.strictEqual(async.eachSeries, async.forEachSeries);
test.done();
Expand Down Expand Up @@ -1668,6 +1728,29 @@ exports['mapLimit error'] = function(test){
setTimeout(test.done, 25);
};

exports['mapLimit does not continue replenishing after error'] = function (test) {
var started = 0;
var arr = [0,1,2,3,4,5,6,7,8,9];
var delay = 10;
var limit = 3;
var maxTime = 10 * arr.length;

async.mapLimit(arr, limit, function(x, callback) {
started ++;
if (started === 3) {
return callback(new Error ("Test Error"));
}
setTimeout(function(){
callback();
}, delay);
}, function(err){});

setTimeout(function(){
test.equal(started, 3);
test.done();
}, maxTime);
};


exports['reduce'] = function(test){
var call_order = [];
Expand Down