Skip to content

Instantly share code, notes, and snippets.

@dtinth
Created October 19, 2011 12:55
Show Gist options
  • Save dtinth/1298205 to your computer and use it in GitHub Desktop.
Save dtinth/1298205 to your computer and use it in GitHub Desktop.
Async Stuff
var asyncLoop = function(init, cond, next, body, fin) {
init();
if (cond()) body(function cont() {
next(); if (cond()) body(cont); else if (fin) fin();
});
};
var asyncSeq = function() {
var i, args = arguments;
asyncLoop(
function() { i = 0; },
function() { return i < args.length; },
function() { i ++; },
function(cont) {
console.log(i);
args[i](cont);
}
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment