Created
March 2, 2011 21:49
-
-
Save indexzero/851816 to your computer and use it in GitHub Desktop.
A somewhat generic async setup script in node.js for @brianlovesdata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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