summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/async.js53
1 files changed, 24 insertions, 29 deletions
diff --git a/lib/async.js b/lib/async.js
index 0cde368..52f5f2c 100644
--- a/lib/async.js
+++ b/lib/async.js
@@ -814,43 +814,38 @@
async.during = function (test, iterator, callback) {
callback = callback || noop;
- test(function(err, truth) {
+
+ var next = _restParam(function(err, args) {
if (err) {
- return callback(err);
- }
- if (truth) {
- iterator(function (err) {
- if (err) {
- return callback(err);
- }
- async.during(test, iterator, callback);
- });
+ callback(err);
+ } else {
+ args.push(check);
+ test.apply(this, args);
}
- else {
+ });
+
+ var check = function(err, truth) {
+ if (err) {
+ callback(err);
+ } else if (truth) {
+ iterator(next);
+ } else {
callback(null);
}
- });
+ };
+
+ test(check);
};
async.doDuring = function (iterator, test, callback) {
- callback = callback || noop;
- iterator(_restParam(function (err, args) {
- if (err) {
- return callback(err);
+ var calls = 0;
+ async.during(function(next) {
+ if (calls++ < 1) {
+ next(null, true);
+ } else {
+ test.apply(this, arguments);
}
- args.push(function (err, truth) {
- if (err) {
- return callback(err);
- }
- if (truth) {
- async.doDuring(iterator, test, callback);
- }
- else {
- callback(null);
- }
- });
- test.apply(null, args);
- }));
+ }, iterator, callback);
};
function _queue(worker, concurrency, payload) {