Created
May 21, 2014 09:49
-
-
Save jan-swiecki/2c379ccf321d029e6646 to your computer and use it in GitHub Desktop.
asyncLoop.js
This file contains 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
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