Skip to content

Instantly share code, notes, and snippets.

@hemanth
Created July 3, 2012 06:02
Show Gist options
  • Select an option

  • Save hemanth/3037985 to your computer and use it in GitHub Desktop.

Select an option

Save hemanth/3037985 to your computer and use it in GitHub Desktop.
split up iterating over an array with setTimeout
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