Skip to content

Instantly share code, notes, and snippets.

@jan-swiecki
Created May 21, 2014 09:49
Show Gist options
  • Save jan-swiecki/2c379ccf321d029e6646 to your computer and use it in GitHub Desktop.
Save jan-swiecki/2c379ccf321d029e6646 to your computer and use it in GitHub Desktop.
asyncLoop.js
function asyncLoop(index, callback) {
if(index+1) {
setTimeout(function() {
callback(index);
asyncLoop(index-1, callback);
}, 10);
}
}
// sync
var i = 10
while(i--) {
something(i);
}
// async
asyncLoop(10, function(i) {
something(i);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment