JavaScript › Event Loop & Concurrency
What is 'starvation' of the macrotask queue, and how can recursive microtasks cause it?
AdvancedAnswer
Because ALL pending microtasks are drained before the next macrotask runs, code that keeps scheduling new microtasks from within a microtask (e.g. a Promise chain that queues another .then() indefinitely) can starve macrotasks — including rendering and setTimeout callbacks — from ever running.
function foreverMicrotask() {
Promise.resolve().then(foreverMicrotask); // never lets a macrotask run
}
foreverMicrotask(); // freezes rendering indefinitelyReal-world example Debugging a page that becomes completely unresponsive due to a recursive .then() chain with no exit condition.