Skip to content

Instantly share code, notes, and snippets.

@nicksahler
Last active December 22, 2015 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicksahler/6408468 to your computer and use it in GitHub Desktop.
Save nicksahler/6408468 to your computer and use it in GitHub Desktop.
Async flow control thingy
module.exports = function (functions, callback) {
var i = 0, args;
(function it(err) {
args = Array.prototype.slice.call(arguments);
args.shift();
if (i < functions.length && !err) {
try {
functions[i++].apply(this, [it].concat(args));
} catch (e) {
callback(e, args);
}
} else {
(callback?callback:function(){})(err, args);
}
})();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment