MotionScript

@motion-script/core


@motion-script/core / yieldToScheduler

Function: yieldToScheduler()

yieldToScheduler(): Promise<void>

Defined in: util/scheduler.ts:71

Yield to the event loop, letting pending input, timers and rendering run before the caller resumes.

Deliberately a macrotask, not a microtask: await Promise.resolve() drains within the same task and would starve exactly the work we're yielding for. requestAnimationFrame is also wrong here — it caps throughput to the display rate and stops entirely in a background tab, which would stall headless export and tests.

Preference order:

  1. scheduler.yield() — resumes at continuation priority, so a sliced task isn't starved behind unrelated work queued while it was parked.
  2. MessageChannel — a true macrotask with no clamping, in browsers and Node ≥ 15.
  3. setTimeout(0) — last resort; clamps to ~4 ms once nested, capping the slice rate, but always available.

Returns

Promise<void>