Permalink
Browse files

Remove `.forEach()`

  • Loading branch information...
1 parent 50b2394 commit 25c4487275917dccae0064a289584db29136adee @hokaccha committed Mar 17, 2012
Showing with 0 additions and 159 deletions.
  1. +0 −84 lib/chain-tiny.js
  2. +0 −75 test/forEach.js
View
@@ -78,60 +78,6 @@ Chain.prototype.end = function(fn) {
};
-/**
- * Iterator function to each item in an array. Array recieved before next function args.
- *
- * @param {Function} fn
- * @return {Object} chain
- * @api public
- */
-Chain.prototype.forEach = function(fn) {
- var self = this;
-
- return self.chain(function(ary, next) {
- var _chain = Chain();
- var results = [];
- ary.forEach(function(val) {
- _chain.chain(function(_next) {
- fn.call(null, val, function(err, result) {
- results.push(result);
- _next(err);
- });
- });
- });
- _chain.end(function(err) {
- next(err, results);
- });
- });
-};
-
-
-/**
- * Iterator function to each item in an array parallel. Array recieved before next function args.
- *
- * @param {Function} fn
- * @return {Object} chain
- * @api public
- */
-Chain.prototype.forEachParallel = function(fn) {
- var self = this;
-
- return self.chain(function(ary, next) {
- var _chain = Chain();
- var q = [];
- ary.forEach(function(val) {
- q.push(function(_next) {
- fn.call(null, val, function(err, result) {
- _next(err, result);
- });
- });
- });
-
- Chain.parallel(q).end(next);
- });
-};
-
-
/**
*
* Iterator function to each item in an object (plain hash). Array recieved before next function args.
@@ -251,36 +197,6 @@ Chain.prototype.wait = function(time) {
};
-/**
- * Static method for `.forEach()`.
- *
- * @param {Array} ary
- * @param {Function} fn
- * @return {Object} chain
- * @api public
- */
-Chain.forEach = function(ary, fn) {
- return Chain(function(next) {
- next(null, ary);
- }).forEach(fn);
-};
-
-
-/**
- * Static method for `.forEachParallel()`.
- *
- * @param {Array} ary
- * @param {Function} fn
- * @return {Object} chain
- * @api public
- */
-Chain.forEachParallel = function(ary, fn) {
- return Chain(function(next) {
- next(null, ary);
- }).forEachParallel(fn);
-};
-
-
/**
* Static method for `.each()`.
*
View
@@ -1,75 +0,0 @@
-var nodeunit = require('nodeunit');
-var chain = require('../index');
-
-module.exports = nodeunit.testCase({
- '.forEach()': function(t) {
- var start = Date.now();
- chain(function(next) {
- next(null, ['foo', 'bar']);
- })
- .forEach(function(val, next) {
- setTimeout(function() {
- next(null, val);
- }, 100);
- })
- .chain(function(results, next) {
- t.equal(results.length, 2);
- t.equal(results[0], 'foo');
- t.equal(results[1], 'bar');
- t.ok(Date.now() - start >= 190);
- t.done();
- })
- .end(t.done);
- },
- '.forEachParallel()': function(t) {
- var start = Date.now();
- chain(function(next) {
- next(null, ['foo', 'bar']);
- })
- .forEachParallel(function(val, next) {
- setTimeout(function() {
- next(null, val);
- }, 100);
- })
- .chain(function(results, next) {
- t.equal(results.length, 2);
- 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(val, next) {
- setTimeout(function() {
- next(null, val);
- }, 100);
- })
- .chain(function(results, next) {
- t.equal(results.length, 2);
- 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(val, next) {
- setTimeout(function() {
- next(null, val);
- }, 100);
- })
- .chain(function(results, next) {
- t.equal(results.length, 2);
- t.equal(results[0], 'foo');
- t.equal(results[1], 'bar');
- t.ok(Date.now() - start < 190);
- next();
- })
- .end(t.done);
- }
-});

0 comments on commit 25c4487

Please sign in to comment.