Dev.Lib
arrow_backBack to Blogs
LEVEL_088.1June 27, 20261 min read

Task starvation

Concurrency & Streams

Low-priority tasks never run if high-priority work always pending — infinite transition updates starve idle cleanup.

Summary

Low-priority tasks never run if high-priority work always pending — infinite transition updates starve idle cleanup. Scheduler starvation also on main thread: tight loop blocks microtasks/macrotasks. Yield with setTimeout(0), scheduler.postTask, or break work. Symptom: loading spinner stuck, analytics never fires.

Code example

async function processQueue(tasks) {
  for (const task of tasks) {
    await new Promise((resolve) => setTimeout(resolve, 0)); // yield macrotask
    task();
  }
}

Key points

  • Low-priority tasks never run if high-priority work always pending — infinite transition updates starve idle cleanup.
  • Scheduler starvation also on main thread: tight loop blocks microtasks/macrotasks.
  • Yield with setTimeout(0), scheduler.postTask, or break work.
  • Symptom: loading spinner stuck, analytics never fires.

Further reading

Related concepts