Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485/** Test-only scheduling helpers shared by this package's unit tests. Gates make concurrency tests deterministic: each scheduled call blocks on its own gate, and the test releases gates one at a time in a chosen order, so start and settle sequences are decided by the test rather than by scheduler timing. @module */
import { wait, } from '@monochromatic-dev/module-async-time/ts';
//region Gates
/** One controllable completion gate: a blocked call awaits `open`, the test finishes it with `release`. @example ```ts const gate = createGate(); await gate.open; ``` */export type Gate = { /** Promise settled by {@link Gate.release}. */ readonly open: Promise<void>; /** Settles {@link Gate.open}, letting the blocked call continue. */ readonly release: () => void;};
/** Creates one openable gate. @returns Gate whose promise is pending until released. @example ```ts const gate = createGate(); gate.release(); await gate.open; ``` */export function createGate(): Gate { /** Deferred pair backing the gate's promise and its release. */ const deferred = Promise.withResolvers<void>(); return { open: deferred.promise, release: function release(): void { deferred.resolve(); }, };}
//endregion Gates
//region Turns
/** Yields one macrotask turn. A `setTimeout` turn runs after every queued microtask, so awaiting this guarantees the run's detached mapper continuations and pulls have all run. @example ```ts await yieldTurn(); startedIds; // reflects every mapper call the run started ``` */export async function yieldTurn(): Promise<void> { await wait( 0, );}
//endregion Turns