[Pkg-javascript-commits] [node-async] 415/480: Track auto tasks using a counter to allow records to be inserted/removed from results
Jonas Smedegaard
js at moszumanska.debian.org
Fri May 2 08:58:47 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository node-async.
commit f1f9bfe9950b126da81ee3fe6bd16d891138ab87
Author: Jesse Houchins <jesse.houchins at tstmedia.com>
Date: Fri Mar 28 16:58:51 2014 -0500
Track auto tasks using a counter to allow records to be inserted/removed from results
---
lib/async.js | 6 ++++--
test/test-async.js | 25 +++++++++++++++++++++++++
2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/lib/async.js b/lib/async.js
index 64398b9..42b2621 100755
--- a/lib/async.js
+++ b/lib/async.js
@@ -402,7 +402,8 @@
async.auto = function (tasks, callback) {
callback = callback || function () {};
var keys = _keys(tasks);
- if (!keys.length) {
+ var remainingTasks = keys.length
+ if (!remainingTasks) {
return callback(null);
}
@@ -421,13 +422,14 @@
}
};
var taskComplete = function () {
+ remainingTasks--
_each(listeners.slice(0), function (fn) {
fn();
});
};
addListener(function () {
- if (_keys(results).length === keys.length) {
+ if (!remainingTasks) {
var theCallback = callback;
// prevent final callback from calling itself if it errors
callback = function () {};
diff --git a/test/test-async.js b/test/test-async.js
index f7eca6d..32a6cba 100755
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -554,6 +554,31 @@ exports['auto calls callback multiple times'] = function(test) {
}, 10);
};
+// Issue 462 on github: https://github.com/caolan/async/issues/462
+exports['auto modifying results causes final callback to run early'] = function(test) {
+ async.auto({
+ task1: function(callback, results){
+ results.inserted = true
+ callback(null, 'task1');
+ },
+ task2: function(callback){
+ setTimeout(function(){
+ callback(null, 'task2');
+ }, 50);
+ },
+ task3: function(callback){
+ setTimeout(function(){
+ callback(null, 'task3');
+ }, 100);
+ }
+ },
+ function(err, results){
+ test.equal(results.inserted, true)
+ test.ok(results.task3, 'task3')
+ test.done();
+ });
+};
+
exports['waterfall'] = function(test){
test.expect(6);
var call_order = [];
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-async.git
More information about the Pkg-javascript-commits
mailing list