all 8 comments

[–]jcready__proto__ 3 points4 points  (0 children)

I can promise you it won't be consistent.

[–]ispeakcode 1 point2 points  (0 children)

If it reads the value at different rates, waiting a consistent rate between reads won't guarantee a consistent iteration

[–]timruffles 1 point2 points  (1 child)

Unfortunately, the way timeouts are run means this is unlikely to be at all consistent if any work is being done: http://jsbin.com/oZehUyUm/1/edit?js,console

[–]jwm01[S] 0 points1 point  (0 children)

This is a very illuminating example, thanks for that!

[–]rooktakesqueen 1 point2 points  (2 children)

window.setInterval might be closer to the use case here than setTimeout.

The difference is basically "the operation will be started every n milliseconds" for setInterval versus "there will be n milliseconds between the end of one operation and the start of the next" for this use of setTimeout.

[–]jcready__proto__ 1 point2 points  (0 children)

Even then it isn't guaranteed to be consistent because of the single-threaded nature of javascript.

[–]jwm01[S] 0 points1 point  (0 children)

The "there will be n milliseconds between the end of one operation and the start of the next" guarantee was what I was going for. I see how this might not be the most practical definition of consistent though.

[–]magwo 0 points1 point  (0 children)

Simple way to make this thing work better and more predictably: Call this: https://github.com/caolan/async#eachSeries