Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Misc changes. Fix for sync callbacks

  • Loading branch information...
commit 61a578ef4e8300f09fb5a8fd2b76c995f35dfc58 1 parent 72fa168
Tim authored
Showing with 25 additions and 27 deletions.
  1. +25 −27 lib/parallel/index.js
52 lib/parallel/index.js
View
@@ -31,37 +31,35 @@ Task.prototype.bind = function bind() {
};
Task.prototype.run = function run(callback) {
- var count = 0,
- action,
- args,
- keys = Object.keys(this.actions),
- self = this;
-
- for (var i = 0, key; key = keys[i++]; ) {
- action = this.actions[key][0];
- args = this.actions[key].slice(1);
- args.push((function(name, action) {
- return function() {
- arguments = Array.prototype.slice.call(arguments);
- arguments.unshift(name);
- self._emitter.emit.apply(self._emitter, arguments);
- callback.apply(self, arguments);
-
- count--;
- if (0 >= count) {
- callback.call(self, null);
- }
- };
- })(key, action));
-
- count++;
- action.apply(exports, args);
- }
+ var keys = Object.keys(this.actions),
+ count = keys.length,
+ self = this;
if (0 >= count) {
callback(null);
+ return this;
}
+ keys.forEach(function (key) {
+ var action = self.actions[key][0],
+ args = self.actions[key].slice(1);
+
+ args.push(function() {
+ arguments = Array.prototype.slice.call(arguments);
+ arguments.unshift(key);
+ console.log(arguments);
+ self._emitter.emit.apply(self._emitter, arguments);
+ callback.apply(self, arguments);
+
+ count--;
+ if (0 >= count) {
+ callback.call(self, null);
+ }
+ });
+
+ action.apply(null, args);
+ });
+
return this;
};
@@ -91,7 +89,7 @@ Sequence.prototype.run = function run(callback) {
var args = Array.prototype.slice.call(arguments);
args.unshift(next);
try {
- task.apply(this, args);
+ task.apply(null, args);
} catch (error) {
next(error)
}
Please sign in to comment.
Something went wrong with that request. Please try again.