Created
March 15, 2020 21:15
-
-
Save emersonbroga/3201fbb44682711e28e866489d28d4f7 to your computer and use it in GitHub Desktop.
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(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