Reputation: 2870
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
Upvotes: 0
Views: 238
Reputation: 5127
setTimeout runs once and is good to use when you either
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.
Upvotes: 5
Reputation: 1062
To answer your other question, there is no difference besides the already mentioned one, both get the same priority.
Upvotes: 0