Skip to content

Instantly share code, notes, and snippets.

@bmatusiak
Created November 24, 2012 21:45
Show Gist options
  • Save bmatusiak/4141510 to your computer and use it in GitHub Desktop.
Save bmatusiak/4141510 to your computer and use it in GitHub Desktop.
inline async js
module.exports = function inline(functions){
/*
,function(next,done){
//
next();
}
*/
functions.reverse();
return function(done) {
var fn = [];
var count = 0;
for (var i = 0; i < functions.length; i++) {
fn.push(functions[i]);
}
var next = function() {
var curFN = fn.pop();
++count;
if (count == functions.length) {
if(done) curFN(done,done);
}
else {
curFN(next,done);
}
};
if (fn.length >= 1) {
next();
}
else {
if(done) done();
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment