// process.nextTick for builtins defined at module scope (streams, http). The worker // binds the event loop's queue once at boot; until then ticks are microtasks. import { capture, runInFrame } from "./async_hooks"; type Tick = (fn: () => void) => void; let impl: Tick = queueMicrotask; export function nextTick(fn: () => void): void { // Captured here, at the call that schedules it, not inside `impl` — `impl` is // `loop.nextTick` once the loop binds, which captures again (harmless: by then // the frame is already the one we just restored) and is a bare queueMicrotask // before that, which captures nothing on its own. const frame = capture(); impl(() => runInFrame(frame, fn)); } export function useNextTick(tick: Tick): void { impl = tick; }