[Pkg-javascript-commits] [node-async] 465/480: for #521, detect callback in _asyncMap

Jonas Smedegaard js at moszumanska.debian.org
Fri May 2 08:58:52 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 18fd0cc3f13f0a97ed7d29f96aedb2f3740b36b2
Author: fritx <uxfritz at 163.com>
Date:   Tue Apr 29 00:35:28 2014 +0800

    for #521, detect callback in _asyncMap
---
 lib/async.js       | 24 ++++++++++++++++--------
 test/test-async.js | 13 +++++++++++++
 2 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/lib/async.js b/lib/async.js
index a1d1d6a..b1e4ae5 100755
--- a/lib/async.js
+++ b/lib/async.js
@@ -234,18 +234,26 @@
 
 
     var _asyncMap = function (eachfn, arr, iterator, callback) {
-        var results = [];
         arr = _map(arr, function (x, i) {
             return {index: i, value: x};
         });
-        eachfn(arr, function (x, callback) {
-            iterator(x.value, function (err, v) {
-                results[x.index] = v;
-                callback(err);
+        if (!callback) {
+            eachfn(arr, function (x, callback) {
+                iterator(x.value, function (err) {
+                    callback(err);
+                });
             });
-        }, function (err) {
-            callback(err, results);
-        });
+        } else {
+            var results = [];
+            eachfn(arr, function (x, callback) {
+                iterator(x.value, function (err, v) {
+                    results[x.index] = v;
+                    callback(err);
+                });
+            }, function (err) {
+                callback(err, results);
+            });
+        }
     };
     async.map = doParallel(_asyncMap);
     async.mapSeries = doSeries(_asyncMap);
diff --git a/test/test-async.js b/test/test-async.js
index d9f2dee..cbdd7ce 100755
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -1236,6 +1236,19 @@ exports['map original untouched'] = function(test){
     });
 };
 
+exports['map without main callback'] = function(test){
+    var a = [1,2,3];
+    var r = [];
+    async.map(a, function(x, callback){
+        r.push(x);
+        callback(null);
+        if (r.length >= a.length) {
+            test.same(r, a);
+            test.done();
+        }
+    });
+};
+
 exports['map error'] = function(test){
     test.expect(1);
     async.map([1,2,3], function(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