Skip to content
Browse files

renamed reduceSeries to reduce

  • Loading branch information...
1 parent 502d47a commit 9e41a5fa71325e96fce36988d6ba01654dde9149 @caolan committed Jun 1, 2010
Showing with 10 additions and 20 deletions.
  1. +4 −4 lib/async.js
  2. +6 −16 test/test-async.js
View
8 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){
View
22 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');

0 comments on commit 9e41a5f

Please sign in to comment.
Something went wrong with that request. Please try again.