Skip to content

Commit

Permalink
Add Step
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Mar 18, 2010
1 parent 987651c commit 186c28c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions step.js
@@ -0,0 +1,27 @@
// Inspired by http://github.com/willconant/flow-js
function Step() {
var steps = Array.prototype.slice.call(arguments);
var counter;
var results;

function next(result) {
if (steps.length <= 0) { return; }
var fn = steps.shift();
counter = 0;
results = [];
fn.apply(next, result);
}
next.parallel = function () {
counter++;
return function () {
counter--;
results.push(arguments);
if (counter <= 0) {
next(results);
}
}
};

next([]);
}
module.exports = Step;

0 comments on commit 186c28c

Please sign in to comment.