A somewhat generic async setup script in node.js for @brianlovesdata
var async = require('async');
exports.start = function (options, callback) {
//
// Create an array of all your setup functions
//
var setupFns = [
fn1,
fn2,
fn3,
fn4,
fn5
];
//
// ### function runSetupFn (fn, next)
// #### @fn {function} An individual setup function
// #### @next {function} Iteration Continuation
// Runs a single setup function with the options
// hash provided to `.start()`
//
function runSetupFn (fn, next) {
fn(options, function (err) {
return err ? next(err) : next();
});
}
//
// Iterate over the set of `setupFns` in parallel using
// `runSetupFn` as your iterator function.
//
async.forEach(setupFns, runSetupFn, function (err) {
return err ? callback(err) : callback();
});
};