Skip to content

Commit

Permalink
Fix .forEach args remove key
Browse files Browse the repository at this point in the history
  • Loading branch information
hokaccha committed Mar 12, 2012
1 parent 1d8bae5 commit d1ff0c7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions lib/chain-tiny.js
Expand Up @@ -91,9 +91,9 @@ Chain.prototype.forEach = function(fn) {
return self.chain(function(ary, next) {
var _chain = Chain();
var results = [];
ary.forEach(function(val, i) {
ary.forEach(function(val) {
_chain.chain(function(_next) {
fn.call(null, i, val, function(err, result) {
fn.call(null, val, function(err, result) {
results.push(result);
_next(err);
});
Expand All @@ -119,9 +119,9 @@ Chain.prototype.forEachParallel = function(fn) {
return self.chain(function(ary, next) {
var _chain = Chain();
var q = [];
ary.forEach(function(val, i) {
ary.forEach(function(val) {
q.push(function(_next) {
fn.call(null, i, val, function(err, result) {
fn.call(null, val, function(err, result) {
_next(err, result);
});
});
Expand Down
32 changes: 16 additions & 16 deletions test/forEach.js
Expand Up @@ -7,15 +7,15 @@ module.exports = nodeunit.testCase({
chain(function(next) {
next(null, ['foo', 'bar']);
})
.forEach(function(key, val, next) {
.forEach(function(val, next) {
setTimeout(function() {
next(null, key + ':' + val);
next(null, val);
}, 100);
})
.chain(function(results, next) {
t.equal(results.length, 2);
t.equal(results[0], '0:foo');
t.equal(results[1], '1:bar');
t.equal(results[0], 'foo');
t.equal(results[1], 'bar');
t.ok(Date.now() - start >= 190);
t.done();
})
Expand All @@ -26,47 +26,47 @@ module.exports = nodeunit.testCase({
chain(function(next) {
next(null, ['foo', 'bar']);
})
.forEachParallel(function(key, val, next) {
.forEachParallel(function(val, next) {
setTimeout(function() {
next(null, key + ':' + val);
next(null, val);
}, 100);
})
.chain(function(results, next) {
t.equal(results.length, 2);
t.equal(results[0], '0:foo');
t.equal(results[1], '1:bar');
t.equal(results[0], 'foo');
t.equal(results[1], 'bar');
t.ok(Date.now() - start < 190);
next();
})
.end(t.done);
},
'Chain.forEach()': function(t) {
var start = Date.now();
chain.forEach(['foo', 'bar'], function(key, val, next) {
chain.forEach(['foo', 'bar'], function(val, next) {
setTimeout(function() {
next(null, key + ':' + val);
next(null, val);
}, 100);
})
.chain(function(results, next) {
t.equal(results.length, 2);
t.equal(results[0], '0:foo');
t.equal(results[1], '1:bar');
t.equal(results[0], 'foo');
t.equal(results[1], 'bar');
t.ok(Date.now() - start >= 190);
next();
})
.end(t.done);
},
'Chain.forEachParallel()': function(t) {
var start = Date.now();
chain.forEachParallel(['foo', 'bar'], function(key, val, next) {
chain.forEachParallel(['foo', 'bar'], function(val, next) {
setTimeout(function() {
next(null, key + ':' + val);
next(null, val);
}, 100);
})
.chain(function(results, next) {
t.equal(results.length, 2);
t.equal(results[0], '0:foo');
t.equal(results[1], '1:bar');
t.equal(results[0], 'foo');
t.equal(results[1], 'bar');
t.ok(Date.now() - start < 190);
next();
})
Expand Down

0 comments on commit d1ff0c7

Please sign in to comment.