/** Default time budget, in milliseconds, a caller may run before {@link Yielder.maybeYield} yields. */ export declare const DEFAULT_YIELD_BUDGET_MS = 8; export type YielderOptions = { /** Time in milliseconds work may run without a macrotask turn before yielding. Defaults to 8. */ budgetMs?: number; /** Clock returning the current time in milliseconds. Defaults to `Date.now`. */ now?: () => number; /** * Runs a callback on a later macrotask turn. Defaults to the `setTimeout(callback, 0)` found when * the yielder is created, so timers faked or patched afterwards (test fake timers) cannot stall it. */ schedule?: (callback: () => void) => void; }; export type Yielder = { /** * Resolves immediately while a macrotask turn has happened within the budget, otherwise waits * for a macrotask turn. Call between units of work in long async loops. */ maybeYield: () => Promise; }; /** * Creates a cooperative yielder for long-running async loops. * * Promise chains never return to the event loop on their own, so a loop of async work can starve * rendering, I/O and timers. `maybeYield()` tracks when the event loop last completed a macrotask * turn (via a sentinel `setTimeout(…, 0)`) and, once the budget is exceeded, waits for a real * macrotask turn. It deliberately uses `setTimeout` rather than `setImmediate` (which runs before * native events are drained on React Native) or microtasks (which never yield). * * A turn resumes waiters in FIFO order, checking the clock after each waiter's promise * continuation runs. It stops at the budget or after the waiters present at the start of the * turn, then schedules another turn for any remainder. While waiters are queued, new callers * queue behind them even if within budget. */ export declare function createYielder(options?: YielderOptions): Yielder; /** Shared yielder so independent libraries cooperate on a single clock and queue. */ export declare const defaultYielder: Yielder; /** {@link Yielder.maybeYield} of the shared {@link defaultYielder}. */ export declare const maybeYield: () => Promise;