Skip to content

Commit

Permalink
make callbacks optional in whilst and family. Closes #642
Browse files Browse the repository at this point in the history
  • Loading branch information
aearly committed Jun 28, 2015
1 parent 74ad21e commit e37af8d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
New Features:
- `retry` now accepts an `interval` parameter to specify a delay between retries. (#793)
- `async` should work better in Web Workers due to better `root` detection (#804)
- Callbacks are now optional in `whilst`, `doWhilst`, `until`, and `doUntil` (#642)
- Various internal updates (#786, #801, #802, #803)
- Various doc fixes (#790, #794)

Expand Down
4 changes: 4 additions & 0 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@
async.concatSeries = doSeries(_concat);

async.whilst = function (test, iterator, callback) {
callback = callback || noop;
if (test()) {
iterator(function (err) {
if (err) {
Expand All @@ -799,6 +800,7 @@
};

async.doWhilst = function (iterator, test, callback) {
callback = callback || noop;
iterator(function (err) {
if (err) {
return callback(err);
Expand All @@ -814,6 +816,7 @@
};

async.until = function (test, iterator, callback) {
callback = callback || noop;
if (!test()) {
iterator(function (err) {
if (err) {
Expand All @@ -828,6 +831,7 @@
};

async.doUntil = function (iterator, test, callback) {
callback = callback || noop;
iterator(function (err) {
if (err) {
return callback(err);
Expand Down
13 changes: 13 additions & 0 deletions test/test-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -2847,6 +2847,19 @@ exports['doWhilst callback params'] = function (test) {
);
};

exports['whilst optional callback'] = function (test) {
var counter = 0;
async.whilst(
function () { return counter < 2; },
function (cb) {
counter++;
cb();
}
);
test.equal(counter, 2);
test.done();
};

exports['queue'] = {

'queue': function (test) {
Expand Down

0 comments on commit e37af8d

Please sign in to comment.