diff options
author | Alexander Early <alexander.early@gmail.com> | 2015-07-02 00:26:24 -0700 |
---|---|---|
committer | Alexander Early <alexander.early@gmail.com> | 2015-07-02 00:26:24 -0700 |
commit | 69a3b67dc6e93711aa746e41366de3f54ef20704 (patch) | |
tree | d91639f5624f4e7b70d3443796d0c944b83413b5 /lib | |
parent | 9bdbb6452dbfcac9ff2d172489e5e0b639d8b9ff (diff) | |
parent | d565a5099030ae8fae3d66654d753507bb31bd1e (diff) | |
download | async-69a3b67dc6e93711aa746e41366de3f54ef20704.tar.gz |
Merge pull request #824 from megawac/do-via-during
Implement doDuring via during
Diffstat (limited to 'lib')
-rw-r--r-- | lib/async.js | 53 |
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) { |