diff options
author | Michael Leaney <leahcimic@gmail.com> | 2013-02-13 10:20:21 +1100 |
---|---|---|
committer | Michael Leaney <leahcimic@gmail.com> | 2013-02-13 10:20:21 +1100 |
commit | 811f90d52dac6ebf252b6395c9c4bfd65ad9d725 (patch) | |
tree | 344edc2ffd57ef5a407b775520d8ecfd5613cfd0 | |
parent | 847929ccd566fc8c57ed6743f279d6bc90e75366 (diff) | |
download | async-811f90d52dac6ebf252b6395c9c4bfd65ad9d725.tar.gz |
Send results to auto callback when an error occurs
When an error occurs using the auto method, still send the partial
results to the callback.
-rwxr-xr-x | lib/async.js | 2 | ||||
-rwxr-xr-x | test/test-async.js | 19 |
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/async.js b/lib/async.js index 3ebad60..9bcc82e 100755 --- a/lib/async.js +++ b/lib/async.js @@ -426,7 +426,7 @@ var task = (tasks[k] instanceof Function) ? [tasks[k]]: tasks[k]; var taskCallback = function (err) { if (err) { - callback(err); + callback(err, results); // stop subsequent errors hitting callback multiple times callback = function () {}; } diff --git a/test/test-async.js b/test/test-async.js index e9efdd3..b447483 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -293,6 +293,25 @@ exports['auto no callback'] = function(test){ }); }; +exports['auto error should pass partial results'] = function(test) { + async.auto({ + task1: function(callback){ + callback(false, 'result1'); + }, + task2: ['task1', function(callback){ + callback('testerror'); + }], + task3: ['task2', function(callback){ + test.ok(false, 'task3 should not be called'); + }] + }, + function(err, results){ + test.equals(err, 'testerror'); + test.equals(results.task1, 'result1'); + }); + setTimeout(test.done, 100); +}; + // Issue 24 on github: https://github.com/caolan/async/issues#issue/24 // Issue 76 on github: https://github.com/caolan/async/issues#issue/76 exports['auto removeListener has side effect on loop iterator'] = function(test) { |