[Pkg-javascript-commits] [node-async] 205/480: Altered prevention to avoid repeat auto tasks

Jonas Smedegaard js at moszumanska.debian.org
Fri May 2 08:58:26 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 7d1827063ea28bb06b4ac492323c1cdd7b9e5df0
Author: Doug Patti <douglas.patti at gmail.com>
Date:   Sun Jul 15 12:09:48 2012 -0400

    Altered prevention to avoid repeat auto tasks
    
    This occurs when two or more tasks both depend on a single other task and have
    their listeners registered. When the required task finishes, it iterates
    through the listeners and calls them. If the first of the listeners executes its
    task and that task finishes immediately, it too begins to iterate through
    potential tasks to call and calls the other dependent task. Assuming this other
    task does not finish immediately, the call rewinds to the original task, which
    continues its iteration through the listeners. The listener that was removed is
    still present in this scope, and so the task is called a second time.
---
 dist/async.min.js  |  2 +-
 lib/async.js       |  4 +++-
 test/test-async.js | 10 ++++++++--
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/dist/async.min.js b/dist/async.min.js
index 6ba3145..d3262f7 100644
--- a/dist/async.min.js
+++ b/dist/async.min.js
@@ -1 +1 @@
-/*global setTimeout: false, console: false */(function(){var a={},b=this,c=b.async;typeof module!="undefined"&&module.exports?module.exports=a:b.async=a,a.noConflict=function(){return b.async=c,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)},e=function(a,b){if(a.map)return a.map(b);var c=[];return d(a,function(a,d,e){c.push(b(a,d,e))}),c},f=function(a,b,c){return a.reduce?a.reduce(b,c):(d(a,function(a,d,e){c=b(c,a,d,e)}),c)},g=function(a){ [...]
\ No newline at end of file
+/*global setTimeout: false, console: false */(function(){var e={},t=this,n=t.async;typeof module!="undefined"&&module.exports?module.exports=e:t.async=e,e.noConflict=function(){return t.async=n,e};var r=function(e,t){if(e.forEach)return e.forEach(t);for(var n=0;n<e.length;n+=1)t(e[n],n,e)},i=function(e,t){if(e.map)return e.map(t);var n=[];return r(e,function(e,r,i){n.push(t(e,r,i))}),n},s=function(e,t,n){return e.reduce?e.reduce(t,n):(r(e,function(e,r,i){n=t(n,e,r,i)}),n)},o=function(e){ [...]
\ No newline at end of file
diff --git a/lib/async.js b/lib/async.js
index 7cc4f5e..b246c51 100644
--- a/lib/async.js
+++ b/lib/async.js
@@ -380,6 +380,7 @@
         });
 
         _forEach(keys, function (k) {
+            var fired = false;
             var task = (tasks[k] instanceof Function) ? [tasks[k]]: tasks[k];
             var taskCallback = function (err) {
                 if (err) {
@@ -400,7 +401,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);
@@ -409,6 +410,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 52f5536..ccd8df0 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();
     });
 };

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