Why setTimeout
callback is not executing even after the desired delay time.
It is taking more time to execute based on the time to execute the other code of the program.
console.time('CalculateExeutionTime');
console.log("Staring....");
setTimeout(() => {
console.log("Inside setTimeout.");
}, 100);
console.log("Middle...");
let start = 0;
let end = 1000000000;
while(end > start){
start++
}
console.log("End...");
console.timeEnd('CalculateExeutionTime')
Also when I set the time to execute the callback of setTimeout
to zero, still it is not executing.
console.time('CalculateExeutionTime');
console.log("Staring....");
setTimeout(() => {
console.log("Inside setTimeout.");
}, 0);
console.log("Middle...");
let start = 0;
let end = 1000000000;
while(end > start){
start++
}
console.log("End...");
console.timeEnd('CalculateExeutionTime')
Is there any way that makes sure the setTimeout
execute at the after the desired time.