[Pkg-javascript-commits] [node-async] 221/480: Renaming forEachLimit to _forEachLimit, adding mapLimit tests
Jonas Smedegaard
js at moszumanska.debian.org
Fri May 2 08:58:28 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository node-async.
commit eaaad5f07bb07bad276058e15a607b137dee2003
Author: Calvin French-Owen <calvin at segment.io>
Date: Sat Nov 24 00:01:27 2012 -0800
Renaming forEachLimit to _forEachLimit, adding mapLimit tests
---
lib/async.js | 6 ++---
test/test-async.js | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 73 insertions(+), 4 deletions(-)
diff --git a/lib/async.js b/lib/async.js
index aeab289..2de4f24 100644
--- a/lib/async.js
+++ b/lib/async.js
@@ -118,11 +118,11 @@
};
async.forEachLimit = function (arr, limit, iterator, callback) {
- var fn = forEachLimit(limit);
+ var fn = _forEachLimit(limit);
fn.apply(null, [arr, iterator, callback]);
};
- var forEachLimit = function (limit) {
+ var _forEachLimit = function (limit) {
return function (arr, iterator, callback) {
callback = callback || function () {};
@@ -195,7 +195,7 @@
async.mapSeries = doSeries(_asyncMap);
async.mapLimit = function (arr, limit, iterator, callback) {
- var fn = forEachLimit(limit);
+ var fn = _forEachLimit(limit);
return _asyncMap.apply(null, [fn, arr, iterator, callback]);
};
diff --git a/test/test-async.js b/test/test-async.js
index 39ec47d..8706717 100644
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -652,7 +652,7 @@ exports['forEachLimit error'] = function(test){
test.expect(2);
var arr = [0,1,2,3,4,5,6,7,8,9];
var call_order = [];
-
+
async.forEachLimit(arr, 3, function(x, callback){
call_order.push(x);
if (x === 2) {
@@ -730,6 +730,75 @@ exports['mapSeries error'] = function(test){
setTimeout(test.done, 50);
};
+
+exports['mapLimit'] = function(test){
+ var call_order = [];
+ async.mapLimit([1,3,2], 2, mapIterator.bind(this, call_order), function(err, results){
+ test.same(call_order, [1,3,2]);
+ test.same(results, [2,6,4]);
+ test.done();
+ });
+};
+
+exports['mapLimit empty array'] = function(test){
+ test.expect(1);
+ async.mapLimit([], 2, function(x, callback){
+ test.ok(false, 'iterator should not be called');
+ callback();
+ }, function(err){
+ test.ok(true, 'should call callback');
+ });
+ setTimeout(test.done, 25);
+};
+
+exports['mapLimit limit exceeds size'] = function(test){
+ var call_order = [];
+ async.mapLimit([0,1,2,3,4,5,6,7,8,9], 20, mapIterator.bind(this, call_order), function(err, results){
+ test.same(call_order, [0,1,2,3,4,5,6,7,8,9]);
+ test.same(results, [0,2,4,6,8,10,12,14,16,18]);
+ test.done();
+ });
+};
+
+exports['mapLimit limit equal size'] = function(test){
+ var call_order = [];
+ async.mapLimit([0,1,2,3,4,5,6,7,8,9], 10, mapIterator.bind(this, call_order), function(err, results){
+ test.same(call_order, [0,1,2,3,4,5,6,7,8,9]);
+ test.same(results, [0,2,4,6,8,10,12,14,16,18]);
+ test.done();
+ });
+};
+
+exports['mapLimit zero limit'] = function(test){
+ test.expect(2);
+ async.mapLimit([0,1,2,3,4,5], 0, function(x, callback){
+ test.ok(false, 'iterator should not be called');
+ callback();
+ }, function(err, results){
+ test.same(results, []);
+ test.ok(true, 'should call callback');
+ });
+ setTimeout(test.done, 25);
+};
+
+exports['mapLimit error'] = function(test){
+ test.expect(2);
+ var arr = [0,1,2,3,4,5,6,7,8,9];
+ var call_order = [];
+
+ async.mapLimit(arr, 3, function(x, callback){
+ call_order.push(x);
+ if (x === 2) {
+ callback('error');
+ }
+ }, function(err){
+ test.same(call_order, [0,1,2]);
+ test.equals(err, 'error');
+ });
+ setTimeout(test.done, 25);
+};
+
+
exports['reduce'] = function(test){
var call_order = [];
async.reduce([1,2,3], 0, function(a, x, callback){
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-async.git
More information about the Pkg-javascript-commits
mailing list