Let's say I have these this
myInterval=setInterval(funcA,50);
function funcA(){
//Some code that takes longer than 50ms to run
}
setTimeout(function(){clearInterval(myInterval);},10000}
Let's say funcA always takes longer than 50ms to make it simple. Naturally, many funcA runs will pile up and be queued. Will clearInterval remove those queued runs or just stop queuing new ones?
I did make a fiddle to test it, and it turns out clearInterval stops all future execution, even those that have already be queued. I just need to confirm this behavior is consistent (across browsers/platforms).
var myInterval=setInterval(funcA,20);
setTimeout(function(){
clearInterval(myInterval);
console.log('Clearing interval at ' + Date.now());
},400);
var lastRunTimeStamp=0;
function funcA(){
while(Date.now()<lastRunTimeStamp+25){}
lastRunTimeStamp=Date.now();
console.log('Run at ' + lastRunTimeStamp);
}
--Update--
The queued execution assumption in this question is incorrect, please check T.J. Crowder answer for an explanation.