Skip to content

Commit

Permalink
Merge pull request #993 from gr2m/master
Browse files Browse the repository at this point in the history
auto stops after error #988
  • Loading branch information
aearly committed Jan 2, 2016
2 parents b9cc289 + f360e0d commit 1604c74
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@
var results = {};
var runningTasks = 0;

var hasError = false;

var listeners = [];
function addListener(fn) {
listeners.unshift(fn);
Expand All @@ -550,6 +552,7 @@
});

_arrayEach(keys, function (k) {
if (hasError) return;
var task = _isArray(tasks[k]) ? tasks[k]: [tasks[k]];
var taskCallback = _restParam(function(err, args) {
runningTasks--;
Expand All @@ -562,6 +565,8 @@
safeResults[rkey] = val;
});
safeResults[k] = args;
hasError = true;

callback(err, safeResults);
}
else {
Expand Down
16 changes: 16 additions & 0 deletions test/test-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,22 @@ exports['auto prevent dead-locks due to cyclic dependencies'] = function(test) {
test.done();
};

// Issue 988 on github: https://github.com/caolan/async/issues/988
exports['auto stops running tasks on error'] = function(test) {
async.auto({
task1: function (callback) {
callback('error');
},
task2: function (callback) {
test.ok(false, 'test2 should not be called');
callback();
}
}, 1, function (error) {
test.equal(error, 'error', 'finishes with error');
test.done();
});
};

// Issue 306 on github: https://github.com/caolan/async/issues/306
exports['retry when attempt succeeds'] = function(test) {
var failed = 3;
Expand Down

0 comments on commit 1604c74

Please sign in to comment.