diff --git a/lib/async.js b/lib/async.js index 5da362214..abd4b6c11 100644 --- a/lib/async.js +++ b/lib/async.js @@ -791,31 +791,26 @@ async.whilst = function (test, iterator, callback) { callback = callback || noop; if (test()) { - iterator(function (err) { + var next = _restParam(function(err, args) { if (err) { - return callback(err); + callback(err); + } else if (test.apply(this, args)) { + iterator(next); + } else { + callback(null); } - async.whilst(test, iterator, callback); }); - } - else { + iterator(next); + } else { callback(null); } }; async.doWhilst = function (iterator, test, callback) { - callback = callback || noop; - iterator(_restParam(function (err, args) { - if (err) { - return callback(err); - } - if (test.apply(null, args)) { - async.doWhilst(iterator, test, callback); - } - else { - callback(null); - } - })); + var calls = 0; + return async.whilst(function() { + return ++calls <= 1 || test.apply(this, arguments); + }, iterator, callback); }; async.until = function (test, iterator, callback) {