Timers: setTimeout/setInterval and Drift
On this page
Timers and the Event Loop
Timers schedule delayed execution but interact directly with the event loop. Misuse can increase latency under load.
setTimeout(() => {
console.log('Delayed');
}, 1000);
setImmediate vs setTimeout
setImmediate executes after I/O callbacks. It is useful for deferring heavy computations.
Production Risks
Long-running timer callbacks block the event loop. Heavy tasks should be offloaded to worker threads or external services.