public
Last active

Function to asynchronously iterate over a collection

  • Download Gist
eachAsync.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.