| 'use strict'; | ||
| var qflow = require('../index'); | ||
| module.exports = { | ||
| 'repeatUntil 500k': function(t) { | ||
| var n = 0; | ||
| t.expect(2); | ||
| qflow.repeatUntil( | ||
| function(cb) { | ||
| n++; | ||
| cb(null, n >= 500000); | ||
| }, | ||
| function(err, flag) { | ||
| t.equal(flag, true); | ||
| t.equal(n, 500000); | ||
| t.done(); | ||
| } | ||
| ); | ||
| }, | ||
| }; |
+6
-6
@@ -43,13 +43,14 @@ /** | ||
| function _loop( func, callback, callDepth ) { | ||
| function _loop( callDepth ) { | ||
| try { | ||
| func( function(err, stop) { | ||
| if (alreadyReturned = err || stop) { | ||
| if (err || stop) { | ||
| alreadyReturned = err || stop; | ||
| return callback(err, stop); | ||
| } | ||
| else if (callDepth < 40) { | ||
| _loop(func, callback, callDepth + 1); | ||
| _loop(callDepth + 1); | ||
| } | ||
| else { | ||
| setImmediate(function() { _loop(func, callback, 0); }); | ||
| setImmediate(function() { _loop(0); }); | ||
| } | ||
@@ -71,5 +72,4 @@ } ); | ||
| } | ||
| // note: 2.5x faster if callback is passed in to _loop vs pulled from closure | ||
| _loop(func, callback, 0); | ||
| _loop(0); | ||
| } | ||
@@ -76,0 +76,0 @@ |
+1
-1
| { | ||
| "name": "aflow", | ||
| "version": "0.9.1", | ||
| "version": "0.9.2", | ||
| "description": "async flow control for calls with callbacks", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
25972
1.29%7
16.67%559
3.52%