Created
July 3, 2012 06:02
-
-
Save hemanth/3037985 to your computer and use it in GitHub Desktop.
split up iterating over an array with setTimeout
This file contains hidden or 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 forTimeout(array, iterator, delay) { | |
| void function iteration(index) { | |
| if (index === array.length) return | |
| iterator(array[index]) | |
| setTimeout(function () { iteration(index + 1) }, delay) | |
| }(0) | |
| } | |
| forTimeout([1, 2, 3], function (v) { console.log(v) }, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment