Permalink
Browse files

Refactor order, comments

  • Loading branch information...
1 parent a609593 commit af66c5411e7c4e2ed97d48114892392325f529ca @hokaccha committed Nov 9, 2011
Showing with 53 additions and 34 deletions.
  1. +53 −34 lib/chain-tiny.js
View
@@ -21,11 +21,19 @@ var Chain = function(fn) {
}
};
+
/**
* Module version
*/
Chain.version = '0.1.2';
+
+/**
+ * Expose
+ */
+module.exports = Chain;
+
+
/**
* Function push to stack.
*
@@ -43,6 +51,7 @@ Chain.prototype.chain = function(fn) {
return self;
};
+
/**
* Execute all functions, in the pushed order.
*
@@ -68,6 +77,7 @@ Chain.prototype.end = function(fn) {
})();
};
+
/**
* Iterator function to each item in an array. Array recieved before next function args.
*
@@ -95,6 +105,33 @@ Chain.prototype.forEach = function(fn) {
});
};
+
+/**
+ * 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, i) {
+ q.push(function(_next) {
+ fn.call(null, i, val, function(err, result) {
+ _next(err, result);
+ });
+ });
+ });
+
+ Chain.parallel(q).end(next);
+ });
+};
+
+
/**
* Parallel exec functions.
*
@@ -131,31 +168,6 @@ Chain.prototype.parallel = function(obj) {
});
};
-/**
- * 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, i) {
- q.push(function(_next) {
- fn.call(null, i, val, function(err, result) {
- _next(err, result);
- });
- });
- });
-
- Chain.parallel(q).end(next);
- });
-};
-
/**
* Wait next process during the `time` (ms).
@@ -177,13 +189,9 @@ Chain.prototype.wait = function(time) {
});
};
-// todo doc
-Chain.parallel = function(ary) {
- return Chain().parallel(ary);
-};
/**
- * Iterator function to each item in an array.
+ * Static method for `.forEach()`.
*
* @param {Array} ary
* @param {Function} fn
@@ -196,8 +204,9 @@ Chain.forEach = function(ary, fn) {
}).forEach(fn);
};
+
/**
- * Parallel iterator function to each item in an array.
+ * Static method for `.forEachParallel()`.
*
* @param {Array} ary
* @param {Function} fn
@@ -210,6 +219,19 @@ Chain.forEachParallel = function(ary, fn) {
}).forEachParallel(fn);
};
+
+/**
+ * Static method for `.parallel()`.
+ *
+ * @param {time} Int
+ * @return {Object} chain
+ * @api public
+ */
+Chain.parallel = function(ary) {
+ return Chain().parallel(ary);
+};
+
+
/**
* Static method for `.wait()`.
*
@@ -220,6 +242,3 @@ Chain.forEachParallel = function(ary, fn) {
Chain.wait = function(time) {
return Chain(function(next) { next(null); }).wait(time);
};
-
-
-module.exports = Chain;

0 comments on commit af66c54

Please sign in to comment.