stepup by Adam Crabtree is a simple control-flow library that makes parallel execution, serial execution, and error handling painless. This module originated as step by Tim Caswell and was pretty popular. I liked the stepup fork for the new features that it offers.
npm install stepup
Usage
The most important thing to understand about stepup is that it basically creates and keeps track of callback functions that you can then pass around. Here’s a simple example of reading the content of every file in the current directory.
var stepup = require('stepup'); var fs = require('fs'); stepup([ function ($) { fs.readdir(__dirname, $.first()); }, function ($, files) { // pass down the list of files first $.first()(null, files); // create a group of `first` type of callbacks var stats = $.group('first'); for (var i = 0; i < files.length; i++) { fs.stat(__dirname + '/' + files[i], stats()); } }, function ($, files, stats) { var content = $.group('first'); for (var i = 0; i < files.length; i++) { if (!stats[i].isDirectory()) { fs.readFile(__dirname + '/' + files[i], content()); } } }, function ($, content) { return content.map(function (buf) { return buf.toString(); }); } ], function (err, content) { console.log(content.join('\n-----\n')); });
What Else?
Checkout the runnable example and github example repository.