[Pkg-javascript-commits] [node-async] 78/480: fix bug in order of queue events and improve tests - thanks Kami

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 02531670be1d53fd4013cba8233e8c83418579a0
Author: Caolan McMahon <caolan at caolanmcmahon.com>
Date:   Wed Apr 27 13:45:39 2011 -0700

    fix bug in order of queue events and improve tests - thanks Kami
---
 dist/async.min.js  |  2 +-
 lib/async.js       |  2 +-
 package.json       |  2 +-
 test/test-async.js | 50 ++++++++++++++++++++++++++++++++++++--------------
 4 files changed, 39 insertions(+), 17 deletions(-)

diff --git a/dist/async.min.js b/dist/async.min.js
index c25ae30..f89741e 100644
--- a/dist/async.min.js
+++ b/dist/async.min.js
@@ -1 +1 @@
-/*global setTimeout: false, console: false */(function(){var a={};var b=this,c=b.async;typeof module!=="undefined"&&module.exports?module.exports=a:b.async=a,a.noConflict=function(){b.async=c;return a};var d=function(a,b){if(a.forEach)return a.forEach(b);for(var c=0;c<a.length;c+=1)b(a[c],c,a)};var e=function(a,b){if(a.map)return a.map(b);var c=[];d(a,function(a,d,e){c.push(b(a,d,e))});return c};var f=function(a,b,c){if(a.reduce)return a.reduce(b,c);d(a,function(a,d,e){c=b(c,a,d,e)});ret [...]
\ No newline at end of file
+/*global setTimeout: false, console: false */(function(){var a={};var b=this,c=b.async;typeof module!=="undefined"&&module.exports?module.exports=a:b.async=a,a.noConflict=function(){b.async=c;return a};var d=function(a,b){if(a.forEach)return a.forEach(b);for(var c=0;c<a.length;c+=1)b(a[c],c,a)};var e=function(a,b){if(a.map)return a.map(b);var c=[];d(a,function(a,d,e){c.push(b(a,d,e))});return c};var f=function(a,b,c){if(a.reduce)return a.reduce(b,c);d(a,function(a,d,e){c=b(c,a,d,e)});ret [...]
\ No newline at end of file
diff --git a/lib/async.js b/lib/async.js
index 9be463e..8c863ac 100644
--- a/lib/async.js
+++ b/lib/async.js
@@ -561,13 +561,13 @@
                 if (workers < q.concurrency && tasks.length) {
                     var task = tasks.splice(0, 1)[0];
                     if(q.empty && tasks.length == 0) q.empty();
-                    if(q.drain && tasks.length + workers == 0) q.drain();
                     workers += 1;
                     worker(task.data, function () {
                         workers -= 1;
                         if (task.callback) {
                             task.callback.apply(task, arguments);
                         }
+                        if(q.drain && tasks.length + workers == 0) q.drain();
                         q.process();
                     });
                 }
diff --git a/package.json b/package.json
index eda4068..f995464 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
 , "description": "Higher-order functions and common patterns for asynchronous code"
 , "main": "./index"
 , "author": "Caolan McMahon"
-, "version": "0.1.8"
+, "version": "0.1.9"
 , "repository" :
   { "type" : "git"
   , "url" : "http://github.com/caolan/async.git"
diff --git a/test/test-async.js b/test/test-async.js
index a0d5393..787e5a4 100644
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -1321,25 +1321,47 @@ exports['falsy return values in parallel'] = function (test) {
 };
 
 exports['queue events'] = function(test) {
-    test.expect(3);
+    var calls = [];
     var q = async.queue(function(task, cb) {
         // nop
+        calls.push('process ' + task);
         cb();
     }, 3);
-    
+
     q.saturated = function() {
-       test.ok(q.length() == 3, 'queue should be saturated now');
-    }
+        test.ok(q.length() == 3, 'queue should be saturated now');
+        calls.push('saturated');
+    };
     q.empty = function() {
-       test.ok(q.length() == 0, 'queue should be empty now');
-    }
+        test.ok(q.length() == 0, 'queue should be empty now');
+        calls.push('empty');
+    };
     q.drain = function() {
-       test.ok(q.length() == 0 && q.running() == 0, 'queue should be empty now and no more workers should be running');
-       test.done();
-    }
-    q.push('foo');
-    q.push('bar');
-    q.push('zoo');
-    q.push('poo');
-    q.push('moo');
+        test.ok(
+            q.length() == 0 && q.running() == 0,
+            'queue should be empty now and no more workers should be running'
+        );
+        calls.push('drain');
+        test.same(calls, [
+            'saturated',
+            'process foo',
+            'foo cb',
+            'process bar',
+            'bar cb',
+            'process zoo',
+            'zoo cb',
+            'process poo',
+            'poo cb',
+            'empty',
+            'process moo',
+            'moo cb',
+            'drain',
+        ]);
+        test.done();
+    };
+    q.push('foo', function () {calls.push('foo cb');});
+    q.push('bar', function () {calls.push('bar cb');});
+    q.push('zoo', function () {calls.push('zoo cb');});
+    q.push('poo', function () {calls.push('poo cb');});
+    q.push('moo', function () {calls.push('moo cb');});
 };

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