setTimeout and setInterval What is the difference between, for example, in the long-running function when the UI process?
setTimeout(function(){
/* Some long block of code... */
}, 10);
setInterval(function(){
/* Some long block of code... */
}, 10);
If there is a long execution time, the execution time is greater than setTimeout or setInterval to set the time
setTimeout runs once and is good to use when you either
need to have the call made sequentially
setInterval runs forever until you call clearInterval to cancel.
So, for long running process, it’s good to use setTimeout and then have your setTimeout handler call setTimeout again to keep the loop running.
EDIT
The problem w/ setInterval is that if it takes longer than 10ms (in your case) to run then that next call can be dropped.