Browse files

Add `.parallel` set args

  • Loading branch information...
1 parent 9532702 commit a8a30542769f6394e45716a844356fdc71fa0c5e @hokaccha committed Mar 17, 2012
Showing with 13 additions and 8 deletions.
  1. +4 −3 lib/chain-tiny.js
  2. +9 −5 test/paralle.js
View
7 lib/chain-tiny.js
@@ -150,15 +150,16 @@ Chain.prototype.parallel = function(obj) {
var self = this;
return self.chain(function() {
- var next = Array.prototype.slice.call(arguments).pop();
+ var args = Array.prototype.slice.call(arguments);
+ var next = args.pop();
var count = 0;
var isArray = Array.isArray(obj);
var results = isArray ? [] : {};
var keys = Object.keys(obj);
keys.forEach(function(key) {
var fn = obj[key];
process.nextTick(function() {
- fn.call(null, function _next(err, result) {
+ fn.apply(null, args.concat(function _next(err, result) {
if (err) {
next(err);
}
@@ -169,7 +170,7 @@ Chain.prototype.parallel = function(obj) {
next(null, results);
}
}
- });
+ }));
});
});
});
View
14 test/paralle.js
@@ -8,14 +8,16 @@ module.exports = nodeunit.testCase({
next(null, 'foo');
})
.parallel([
- function(next) {
+ function(val, next) {
setTimeout(function() {
+ t.equal(val, 'foo');
r.push(1);
next(null, 1);
}, 100);
},
- function(next) {
+ function(val, next) {
setTimeout(function() {
+ t.equal(val, 'foo');
r.push(2);
next(null, 2);
}, 1)
@@ -54,17 +56,19 @@ module.exports = nodeunit.testCase({
'Chain.parallel()': function(t) {
var r = [];
chain(function(next) {
- next(null, 'arg');
+ next(null, 'foo');
})
.parallel({
- foo: function(next) {
+ foo: function(val, next) {
setTimeout(function() {
+ t.equal(val, 'foo');
r.push(1);
next(null, 1);
}, 100);
},
- bar: function(next) {
+ bar: function(val, next) {
setTimeout(function() {
+ t.equal(val, 'foo');
r.push(2);
next(null, 2);
}, 1)

0 comments on commit a8a3054

Please sign in to comment.