[Pkg-javascript-commits] [node-async] 18/480: renamed reduceSeries to reduce

Jonas Smedegaard js at moszumanska.debian.org
Fri May 2 08:58:08 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 9e41a5fa71325e96fce36988d6ba01654dde9149
Author: Caolan McMahon <caolan at caolanmcmahon.com>
Date:   Tue Jun 1 12:08:00 2010 +0100

    renamed reduceSeries to reduce
---
 lib/async.js       |  8 ++++----
 test/test-async.js | 22 ++++++----------------
 2 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/lib/async.js b/lib/async.js
index f3fe0fe..e32d7c8 100644
--- a/lib/async.js
+++ b/lib/async.js
@@ -65,8 +65,10 @@ exports.map = doParallel(_map);
 exports.mapSeries = doSeries(_map);
 
 
-var _reduce = function(eachfn, arr, memo, iterator, callback){
-    eachfn(arr, function(x, callback){
+// reduce only has a series version, as doing reduce in parallel won't
+// work in many situations.
+exports.reduce = function(arr, memo, iterator, callback){
+    exports.forEachSeries(arr, function(x, callback){
         iterator(memo, x, function(err, v){
             memo = v;
             callback(err);
@@ -75,8 +77,6 @@ var _reduce = function(eachfn, arr, memo, iterator, callback){
         callback(err, memo);
     });
 };
-exports.reduce = doParallel(_reduce);
-exports.reduceSeries = doSeries(_reduce);
 
 
 var _filter = function(eachfn, arr, iterator, callback){
diff --git a/test/test-async.js b/test/test-async.js
index e07ad82..c7da60b 100644
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -395,28 +395,18 @@ exports['reduce'] = function(test){
     });
 };
 
-exports['reduce error'] = function(test){
-    test.expect(1);
-    async.reduce([1,2,3], 0, function(a, x, callback){
-        callback('error');
-    }, function(err, result){
-        test.equals(err, 'error');
-    });
-    setTimeout(test.done, 50);
-};
-
-exports['reduceSeries'] = function(test){
-    async.reduceSeries([1,3,2], [], function(a, x, callback){
-        callback(null, a.concat(x));
+exports['reduce async with non-reference memo'] = function(test){
+    async.reduce([1,3,2], 0, function(a, x, callback){
+        setTimeout(function(){callback(null, a + x)}, Math.random()*100);
     }, function(err, result){
-        test.same(result, [1,3,2]);
+        test.equals(result, 6);
         test.done();
     });
 };
 
-exports['reduceSeries error'] = function(test){
+exports['reduce error'] = function(test){
     test.expect(1);
-    async.reduceSeries([1,2,3], 0, function(a, x, callback){
+    async.reduce([1,2,3], 0, function(a, x, callback){
         callback('error');
     }, function(err, result){
         test.equals(err, 'error');

-- 
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