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.
In more detail
await scheduler.yield() inside a loop breaks it into short tasks without losing its place in line to other queued work. Check support first; setTimeout is the common fallback.
Related terms
- long task — A task that keeps the main thread busy for more than 50 milliseconds, long enough for users to notice lag.
- 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.
- macrotask — An ordinary task scheduled on the event loop, such as a timer or I/O callback, as opposed to a microtask.
Taught in
- The Browser Event Loop: Call Stack, Microtasks And Macrotasks — Frontend Architecture & Web Platform
- Core Web Vitals: Measuring And Optimizing LCP, INP, And CLS — Frontend Architecture & Web Platform