Created
October 19, 2011 12:55
-
-
Save dtinth/1298205 to your computer and use it in GitHub Desktop.
Async Stuff
This file contains hidden or 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 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