Yes. If a microtask keeps adding more microtasks, the event loop never reaches the macrotask queue. The setTimeout callback is never executed. This is called microtask starvation.
setTimeout and the Event Loop Relationship Explained
Can microtasks starve setTimeout callbacks?
The answer
More FAQs in setTimeout and the Event Loop Relationship Explained
setTimeout hands the timer to a Web API. When the timer fires, the callback is pushed to the macrotask queue. The event loop moves it to the call stack only when the stack is empty and all microtasks are done.
Because promise callbacks go to the microtask queue, which the event loop drains completely before taking one task from the macrotask queue where setTimeout callbacks live.
Yes. If synchronous code is still running, the callback stays in the macrotask queue. The event loop cannot run it until the stack is empty. A 3-second blocking function delays all queued timers by 3 seconds.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.