Node.js - Timers and Scheduling
You want to run a task every 3 seconds but ensure the task never overlaps if it takes longer than 3 seconds. Which approach is best?
setIntervalsetInterval runs tasks at fixed intervals regardless of task duration, causing overlap if task takes longer than interval.setTimeout to control timingsetTimeout schedules the next run only after the current task finishes, preventing overlap.setTimeout scheduling the next call only after task finishes. -> Option A15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions