Skip to content

Instantly share code, notes, and snippets.

@emersonbroga
Created March 15, 2020 21:15
Show Gist options
  • Save emersonbroga/3201fbb44682711e28e866489d28d4f7 to your computer and use it in GitHub Desktop.
Save emersonbroga/3201fbb44682711e28e866489d28d4f7 to your computer and use it in GitHub Desktop.
function asyncLoop(iterations, func, callback) {
var index = 0;
var done = false;
var loop = {
next: function() {
if (done) {
return;
}
if (index < iterations) {
index++;
func(loop);
} else {
done = true;
callback();
}
},
iteration: function() {
return index - 1;
},
break: function() {
done = true;
callback();
}
};
loop.next();
return loop;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment