[Pkg-javascript-commits] [node-async] 84/480: fix parallel implementation of detect when multiple matches occur, closes #28

Jonas Smedegaard js at moszumanska.debian.org
Fri May 2 08:58:14 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 ca4db01269f031322175da2f1f6bec741d6b9dbc
Author: Caolan McMahon <caolan at caolanmcmahon.com>
Date:   Tue May 17 11:36:30 2011 -0700

    fix parallel implementation of detect when multiple matches occur, closes #28
---
 lib/async.js       |  1 +
 test/test-async.js | 44 +++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/lib/async.js b/lib/async.js
index 8c863ac..67de211 100644
--- a/lib/async.js
+++ b/lib/async.js
@@ -247,6 +247,7 @@
             iterator(x, function (result) {
                 if (result) {
                     main_callback(x);
+                    main_callback = function () {};
                 }
                 else {
                     callback();
diff --git a/test/test-async.js b/test/test-async.js
index 8c2cebd..4a7f986 100644
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -181,19 +181,19 @@ exports['parallel'] = function(test){
             setTimeout(function(){
                 call_order.push(1);
                 callback(null, 1);
-            }, 25);
+            }, 50);
         },
         function(callback){
             setTimeout(function(){
                 call_order.push(2);
                 callback(null, 2);
-            }, 50);
+            }, 100);
         },
         function(callback){
             setTimeout(function(){
                 call_order.push(3);
                 callback(null, 3,3);
-            }, 15);
+            }, 25);
         }
     ],
     function(err, results){
@@ -773,6 +773,23 @@ exports['detect'] = function(test){
     }, 100);
 };
 
+exports['detect - mulitple matches'] = function(test){
+    var call_order = [];
+    async.detect([3,2,2,1,2], function(x, callback){
+        setTimeout(function(){
+            call_order.push(x);
+            callback(x == 2);
+        }, x*25);
+    }, function(result){
+        call_order.push('callback');
+        test.equals(result, 2);
+    });
+    setTimeout(function(){
+        test.same(call_order, [1,2,'callback',2,2,3]);
+        test.done();
+    }, 100);
+};
+
 exports['detectSeries'] = function(test){
     var call_order = [];
     async.detectSeries([3,2,1], function(x, callback){
@@ -790,6 +807,23 @@ exports['detectSeries'] = function(test){
     }, 200);
 };
 
+exports['detectSeries - multiple matches'] = function(test){
+    var call_order = [];
+    async.detectSeries([3,2,2,1,2], function(x, callback){
+        setTimeout(function(){
+            call_order.push(x);
+            callback(x == 2);
+        }, x*25);
+    }, function(result){
+        call_order.push('callback');
+        test.equals(result, 2);
+    });
+    setTimeout(function(){
+        test.same(call_order, [3,2,'callback']);
+        test.done();
+    }, 200);
+};
+
 exports['sortBy'] = function(test){
     async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){
         setTimeout(function(){callback(null, x.a);}, 0);
@@ -1275,7 +1309,7 @@ exports['falsy return values in series'] = function (test) {
     async.series(
         [taskFalse, taskUndefined, taskEmpty, taskNull],
         function(err, results) {
-            test.same(results, [false, undefined, undefined, null]);
+            test.equal(results.length, 4);
             test.strictEqual(results[0], false);
             test.strictEqual(results[1], undefined);
             test.strictEqual(results[2], undefined);
@@ -1310,7 +1344,7 @@ exports['falsy return values in parallel'] = function (test) {
     async.parallel(
         [taskFalse, taskUndefined, taskEmpty, taskNull],
         function(err, results) {
-            test.same(results, [false, undefined, undefined, null]);
+            test.equal(results.length, 4);
             test.strictEqual(results[0], false);
             test.strictEqual(results[1], undefined);
             test.strictEqual(results[2], undefined);

-- 
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