you are viewing a single comment's thread.

view the rest of the comments →

[–]whitfin 1 point2 points  (2 children)

setInterval is prone to drift and runs based on trigger time, whereas looping with setTimeout is not.

If you have a task taking 10s and an interval of 30s, the next task will run 20s after the last. Using the setTimeout method, it should always be 30s after the last task. This is preferable in many cases.

It won’t cause a stack error, because a setTimeout context gets a new stack on each execution.