Skip to content

Commit

Permalink
Merge pull request #823 from megawac/do-via-whilst
Browse files Browse the repository at this point in the history
Implement doWhilst via whilst
  • Loading branch information
aearly committed Jul 2, 2015
2 parents fd7a99c + b4059e8 commit 9bdbb64
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,31 +778,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) {
Expand Down

0 comments on commit 9bdbb64

Please sign in to comment.