diff --git a/lib/async.js b/lib/async.js index f6ef7c166..cbd267875 100644 --- a/lib/async.js +++ b/lib/async.js @@ -335,8 +335,8 @@ return fn(async.eachOf, obj, iterator, callback); }; } - function doParallelLimit(limit, fn) { - return function (obj, iterator, callback) { + function doParallelLimit(fn) { + return function (obj, limit, iterator, callback) { return fn(_eachOfLimit(limit), obj, iterator, callback); }; } @@ -361,9 +361,7 @@ async.map = doParallel(_asyncMap); async.mapSeries = doSeries(_asyncMap); - async.mapLimit = function (arr, limit, iterator, callback) { - return doParallelLimit(limit, _asyncMap)(arr, iterator, callback); - }; + async.mapLimit = doParallelLimit(_asyncMap); // reduce only has a series version, as doing reduce in parallel won't // work in many situations. @@ -409,6 +407,9 @@ async.select = async.filter = doParallel(_filter); + async.selectLimit = + async.filterLimit = doParallelLimit(_filter); + async.selectSeries = async.filterSeries = doSeries(_filter); @@ -420,6 +421,7 @@ }, callback); } async.reject = doParallel(_reject); + async.rejectLimit = doParallelLimit(_reject); async.rejectSeries = doSeries(_reject); function _createTester(eachfn, check, getResult) { diff --git a/test/test-async.js b/test/test-async.js index 07b72e7c6..cd7a2a1a0 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -2199,6 +2199,39 @@ exports['rejectSeries'] = function(test){ }); }; +function testLimit(test, arr, limitFunc, limit, iter, done) { + var args = []; + + limitFunc(arr, limit, function(x) { + args.push(x); + iter.apply(this, arguments); + }, function() { + test.same(args, arr); + if (done) done.apply(this, arguments); + else test.done(); + }); +} + +exports['rejectLimit'] = function(test) { + test.expect(2); + testLimit(test, [5, 4, 3, 2, 1], async.rejectLimit, 2, function(v, next) { + next(v % 2); + }, function(x) { + test.same(x, [4, 2]); + test.done(); + }); +}; + +exports['filterLimit'] = function(test) { + test.expect(2); + testLimit(test, [5, 4, 3, 2, 1], async.filterLimit, 2, function(v, next) { + next(v % 2); + }, function(x) { + test.same(x, [5, 3, 1]); + test.done(); + }); +}; + exports['some true'] = function(test){ test.expect(1); async.some([3,1,2], function(x, callback){