summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/async.js4
-rw-r--r--test/test-async.js10
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/async.js b/lib/async.js
index baf5820..b5ba2ea 100644
--- a/lib/async.js
+++ b/lib/async.js
@@ -406,6 +406,7 @@
});
_forEach(keys, function (k) {
+ var fired = false;
var task = (tasks[k] instanceof Function) ? [tasks[k]]: tasks[k];
var taskCallback = function (err) {
if (err) {
@@ -426,7 +427,7 @@
var ready = function () {
return _reduce(requires, function (a, x) {
return (a && results.hasOwnProperty(x));
- }, true) && !results.hasOwnProperty(k);
+ }, true) && !fired;
};
if (ready()) {
task[task.length - 1](taskCallback, results);
@@ -435,6 +436,7 @@
var listener = function () {
if (ready()) {
removeListener(listener);
+ fired = true;
task[task.length - 1](taskCallback, results);
}
};
diff --git a/test/test-async.js b/test/test-async.js
index 69390fa..6cc06e2 100644
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -91,12 +91,18 @@ exports['auto'] = function(test){
callback();
}],
task5: ['task2', function(callback){
- callOrder.push('task5');
+ setTimeout(function(){
+ callOrder.push('task5');
+ callback();
+ }, 0);
+ }],
+ task6: ['task2', function(callback){
+ callOrder.push('task6');
callback();
}]
},
function(err){
- test.same(callOrder, ['task2','task5','task3','task1','task4']);
+ test.same(callOrder, ['task2','task6','task3','task5','task1','task4']);
test.done();
});
};