[Pkg-javascript-commits] [node-async] 223/480: added doWhilst and doUntil

Jonas Smedegaard js at moszumanska.debian.org
Fri May 2 08:58:28 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 fd4166450732049221e979bc90fe69dd8dbd21b4
Author: jkroso <jkroso at gmail.com>
Date:   Thu Nov 29 19:30:43 2012 +1300

    added doWhilst and doUntil
---
 dist/async.min.js  |  1 -
 lib/async.js       | 28 +++++++++++++++++++++++++++
 test/test-async.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+), 1 deletion(-)

diff --git a/dist/async.min.js b/dist/async.min.js
deleted file mode 100644
index 6ba3145..0000000
--- a/dist/async.min.js
+++ /dev/null
@@ -1 +0,0 @@
-/*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
diff --git a/lib/async.js b/lib/async.js
index bbbd05c..d02e23e 100644
--- a/lib/async.js
+++ b/lib/async.js
@@ -556,6 +556,20 @@
         }
     };
 
+    async.doWhilst = function (iterator, test, callback) {
+        iterator(function (err) {
+            if (err) {
+                return callback(err);
+            }
+            if (test()) {
+                async.doWhilst(iterator, test, callback);
+            }
+            else {
+                callback();
+            }
+        });
+    };
+
     async.until = function (test, iterator, callback) {
         if (!test()) {
             iterator(function (err) {
@@ -570,6 +584,20 @@
         }
     };
 
+    async.doUntil = function (iterator, test, callback) {
+        iterator(function (err) {
+            if (err) {
+                return callback(err);
+            }
+            if (!test()) {
+                async.doUntil(iterator, test, callback);
+            }
+            else {
+                callback();
+            }
+        });
+    };
+
     async.queue = function (worker, concurrency) {
         var workers = 0;
         var q = {
diff --git a/test/test-async.js b/test/test-async.js
index 39ec47d..2e849d4 100644
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -1213,6 +1213,34 @@ exports['until'] = function (test) {
     );
 };
 
+exports['doUntil'] = function (test) {
+    var call_order = [];
+    var count = 0;
+    async.doUntil(
+        function (cb) {
+            debugger
+            call_order.push(['iterator', count]);
+            count++;
+            cb();
+        },
+        function () {
+            call_order.push(['test', count]);
+            return (count == 5);
+        },
+        function (err) {
+            test.same(call_order, [
+                ['iterator', 0], ['test', 1],
+                ['iterator', 1], ['test', 2],
+                ['iterator', 2], ['test', 3],
+                ['iterator', 3], ['test', 4],
+                ['iterator', 4], ['test', 5]
+            ]);
+            test.equals(count, 5);
+            test.done();
+        }
+    );
+};
+
 exports['whilst'] = function (test) {
     var call_order = [];
 
@@ -1242,6 +1270,35 @@ exports['whilst'] = function (test) {
     );
 };
 
+exports['doWhilst'] = function (test) {
+    var call_order = [];
+
+    var count = 0;
+    async.doWhilst(
+        function (cb) {
+            call_order.push(['iterator', count]);
+            count++;
+            cb();
+        },
+        function () {
+            call_order.push(['test', count]);
+            return (count < 5);
+        },
+        function (err) {
+            debugger
+            test.same(call_order, [
+                ['iterator', 0], ['test', 1],
+                ['iterator', 1], ['test', 2],
+                ['iterator', 2], ['test', 3],
+                ['iterator', 3], ['test', 4],
+                ['iterator', 4], ['test', 5]
+            ]);
+            test.equals(count, 5);
+            test.done();
+        }
+    );
+};
+
 exports['queue'] = function (test) {
     var call_order = [],
         delays = [160,80,240,80];

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