diff options
author | Alexander Early <aearly@fluid.com> | 2015-06-07 18:10:27 -0700 |
---|---|---|
committer | Alexander Early <aearly@fluid.com> | 2015-06-07 18:13:33 -0700 |
commit | 0ad12379c9d04b824c33c092e955bce1890d075b (patch) | |
tree | c371e85b1723380dd0ae225c99aaf754f1ee505e | |
parent | 88906aa60d407e12185139e86204aa63aa6faf28 (diff) | |
download | async-0ad12379c9d04b824c33c092e955bce1890d075b.tar.gz |
make eachSeries sync w/ single item and a sync iterator. Fixes #782
Conflicts:
test/test-async.js
-rw-r--r-- | lib/async.js | 16 | ||||
-rwxr-xr-x | test/test-async.js | 13 |
2 files changed, 23 insertions, 6 deletions
diff --git a/lib/async.js b/lib/async.js index abc1f7b..c756268 100644 --- a/lib/async.js +++ b/lib/async.js @@ -243,9 +243,9 @@ callback = _once(callback || noop); obj = obj || []; var nextKey = _keyIterator(obj); + var key = nextKey(); function iterate() { var sync = true; - var key = nextKey(); if (key === null) { return callback(null); } @@ -254,11 +254,15 @@ callback(err); } else { - if (sync) { - async.nextTick(iterate); - } - else { - iterate(); + key = nextKey(); + if (key === null) { + return callback(null); + } else { + if (sync) { + async.nextTick(iterate); + } else { + iterate(); + } } } }); diff --git a/test/test-async.js b/test/test-async.js index 670d14a..a69b9e9 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -1477,6 +1477,19 @@ exports['eachSeries array modification'] = function(test) { setTimeout(test.done, 25); }; +// bug #782. Remove in next major release +exports['eachSeries single item'] = function (test) { + test.expect(1); + var sync = true; + async.eachSeries([1], function (i, cb) { + cb(null); + }, function () { + test.ok(sync, "callback not called on same tick"); + }); + sync = false; + test.done(); +}; + exports['eachSeries error'] = function(test){ test.expect(2); var call_order = []; |