cooperative multitasking
A scheduling style where each piece of work voluntarily gives up control after a short time so others can run, instead of being interrupted.
In more detail
If one piece of work never yields, everything else waits. The main thread is cooperative: nothing interrupts your JavaScript, so your code must yield by splitting work or using requestIdleCallback's deadline.
Related terms
- scheduler.yield() — A browser API that pauses a long-running async function so the browser can handle input and rendering, then resumes it with high priority.
- requestIdleCallback — A function that schedules low-priority work to run when the browser has spare time at the end of a frame.
- long task — A task that keeps the main thread busy for more than 50 milliseconds, long enough for users to notice lag.
Taught in
- The Browser Event Loop: Call Stack, Microtasks And Macrotasks — Frontend Architecture & Web Platform
- requestAnimationFrame vs requestIdleCallback: High-FPS Work — Frontend Architecture & Web Platform