diff options
author | Caolan McMahon <caolan@caolanmcmahon.com> | 2012-05-24 00:12:42 -0700 |
---|---|---|
committer | Caolan McMahon <caolan@caolanmcmahon.com> | 2012-05-24 00:12:42 -0700 |
commit | 16b9271e5c684cd7729fa3906032536509e3a4a0 (patch) | |
tree | c1d1b0c6ab3a9b7193ed7aaa77e2e88a0d49ee00 | |
parent | b0aa0f18733bbf0b451f0971dcbd22bbb3060ad0 (diff) | |
download | async-16b9271e5c684cd7729fa3906032536509e3a4a0.tar.gz |
fix occasional synchronous use of forEachLimit
-rw-r--r-- | lib/async.js | 4 | ||||
-rw-r--r-- | test/test-async.js | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/async.js b/lib/async.js index 7021df3..3010bab 100644 --- a/lib/async.js +++ b/lib/async.js @@ -139,7 +139,8 @@ } while (running < limit && started < arr.length) { - iterator(arr[started], function (err) { + started += 1; + iterator(arr[started - 1], function (err) { if (err) { callback(err); callback = function () {}; @@ -155,7 +156,6 @@ } } }); - started += 1; running += 1; } })(); diff --git a/test/test-async.js b/test/test-async.js index ff4b749..ac45272 100644 --- a/test/test-async.js +++ b/test/test-async.js @@ -635,6 +635,18 @@ exports['forEachLimit no callback'] = function(test){ async.forEachLimit([1], 1, forEachNoCallbackIterator.bind(this, test)); }; +exports['forEachLimit synchronous'] = function(test){ + var args = []; + var arr = [0,1,2]; + async.forEachLimit(arr, 5, function(x,callback){ + args.push(x); + callback(); + }, function(err){ + test.same(args, arr); + test.done(); + }); +}; + exports['map'] = function(test){ var call_order = []; async.map([1,3,2], mapIterator.bind(this, call_order), function(err, results){ |