Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created March 2, 2011 21:49
Show Gist options
  • Save indexzero/851816 to your computer and use it in GitHub Desktop.
Save indexzero/851816 to your computer and use it in GitHub Desktop.
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();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment