Created
April 10, 2012 14:52
-
-
Save dtao/2351944 to your computer and use it in GitHub Desktop.
Function to asynchronously iterate over a collection
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 eachAsync(collection, iterator, callback) { | |
var iterate = function(i) { | |
setTimeout(function() { | |
iterator(collection[i]); | |
if (i < collection.length) { | |
iterate(i + 1); | |
} else { | |
callback(); | |
} | |
}, 0); | |
}; | |
iterate(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment