/** A reserved turn in a keyed queue. */ export type QueueSlot = { /** Resolves when every earlier caller on this key has released. */ turn: Promise; /** * Whether the key was free at the instant this slot entered: no earlier caller still * holds it, so `turn` is already destined to resolve and only an external resource can contend. * * Decided SYNCHRONOUSLY, from a count, rather than by racing `turn` against a resolved * sentinel: that would cost extra microtask hops, so a slot behind a fully-released * predecessor would still read as pending, with the verdict depending on timing. */ free: boolean; /** Hand the key to the next caller. Idempotent, and safe to call before the turn arrives. */ release: () => void; }; /** A FIFO queue whose keys run independently. Each queue instance owns its state. */ export type KeyedQueue = { /** Number of keys whose slot chains have not drained yet. */ get size(): number; /** Reserve a slot synchronously. Release it even if its turn is abandoned. */ enter: (key: TKey) => QueueSlot; /** Run a task on its turn, releasing its slot after success or failure. */ run: (key: TKey, fn: () => TResult | PromiseLike) => Promise; }; /** * Create a FIFO queue per key. Failures never block later tasks. * Slot chains only resolve, and drained tails remove their map entries. */ export declare function createKeyedQueue(): KeyedQueue;