[Pkg-javascript-commits] [node-async] 418/480: allow retry to run as an embedded method inside other controll flows

Jonas Smedegaard js at moszumanska.debian.org
Fri May 2 08:58:48 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 17ad7ceae31259b8de4ce79e87639e7d7b3cc846
Author: Jesse Houchins <jesse.houchins at tstmedia.com>
Date:   Fri Mar 28 23:18:44 2014 -0500

    allow retry to run as an embedded method inside other controll flows
---
 lib/async.js | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/lib/async.js b/lib/async.js
index 92c684a..dc235dd 100755
--- a/lib/async.js
+++ b/lib/async.js
@@ -492,20 +492,24 @@
         }
         // Make sure times is a number
         times = parseInt(times, 10) || DEFAULT_TIMES;
-        var retryAttempt = function(task, finalAttempt) {
-            return function(seriesCallback, results) {
-                task(function(err, result){
-                    seriesCallback(!err || finalAttempt, {err: err, result: result});
-                }, results);
+        var wrappedTask = function(wrappedCallback, wrappedResults) {
+            var retryAttempt = function(task, finalAttempt) {
+                return function(seriesCallback) {
+                    task(function(err, result){
+                        seriesCallback(!err || finalAttempt, {err: err, result: result});
+                    }, wrappedResults);
+                };
             };
-        };
-        while (times) {
-            attempts.push(retryAttempt(task, !(times-=1)));
+            while (times) {
+                attempts.push(retryAttempt(task, !(times-=1)));
+            }
+            async.series(attempts, function(done, data){
+                data = data[data.length - 1];
+                (wrappedCallback || callback)(data.err, data.result);
+            });
         }
-        async.series(attempts, function(done, data){
-            data = data[data.length - 1];
-            callback(data.err, data.result);
-        });
+        // If a callback is passed, run this as a controll flow
+        return callback ? wrappedTask() : wrappedTask
     };
 
     async.waterfall = function (tasks, callback) {

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