summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Leaney <leahcimic@gmail.com>2013-02-13 19:50:03 +1100
committerMichael Leaney <leahcimic@gmail.com>2013-02-13 19:50:03 +1100
commitdd7ce2eb799ba3590079487b5e6c53f2157001f4 (patch)
tree11fc34bf18d97aea9bc573215ba94b7312c3862a
parent811f90d52dac6ebf252b6395c9c4bfd65ad9d725 (diff)
downloadasync-dd7ce2eb799ba3590079487b5e6c53f2157001f4.tar.gz
Partial results should include the current task
-rwxr-xr-xlib/async.js15
-rwxr-xr-xtest/test-async.js3
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/async.js b/lib/async.js
index 9bcc82e..a576eee 100755
--- a/lib/async.js
+++ b/lib/async.js
@@ -425,16 +425,21 @@
_each(keys, function (k) {
var task = (tasks[k] instanceof Function) ? [tasks[k]]: tasks[k];
var taskCallback = function (err) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ if (args.length <= 1) {
+ args = args[0];
+ }
if (err) {
- callback(err, results);
+ var safeResults = {};
+ _each(_keys(results), function(rkey) {
+ safeResults[rkey] = results[rkey];
+ });
+ safeResults[k] = args;
+ callback(err, safeResults);
// stop subsequent errors hitting callback multiple times
callback = function () {};
}
else {
- var args = Array.prototype.slice.call(arguments, 1);
- if (args.length <= 1) {
- args = args[0];
- }
results[k] = args;
async.nextTick(taskComplete);
}
diff --git a/test/test-async.js b/test/test-async.js
index b447483..7551de6 100755
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -299,7 +299,7 @@ exports['auto error should pass partial results'] = function(test) {
callback(false, 'result1');
},
task2: ['task1', function(callback){
- callback('testerror');
+ callback('testerror', 'result2');
}],
task3: ['task2', function(callback){
test.ok(false, 'task3 should not be called');
@@ -308,6 +308,7 @@ exports['auto error should pass partial results'] = function(test) {
function(err, results){
test.equals(err, 'testerror');
test.equals(results.task1, 'result1');
+ test.equals(results.task2, 'result2');
});
setTimeout(test.done, 100);
};