/** * The wakes one session owes the model: what is waiting, whether the agent can * take one yet, and which fires may no longer be delivered at all. * * A wake cannot be recalled once pi has it, so the decision to send waits for an * idle agent and is taken here, next to the queue it drains, instead of in the * composition root where the events that set the flag arrive (ADR-0009). * * @author mystery4f <40482524+mystery4f@users.noreply.github.com> */ import type { Iterations } from "./iterations.js"; import type { LoopFire } from "./loop-tasks.js"; export interface WakeDeskOptions { /** Where a dropped wake takes its pending iteration with it. */ readonly iterations: Iterations; /** Hand a wake to pi. Called only for a fire that can still be delivered. */ readonly send: (fire: LoopFire) => void; /** Something left or was dropped: whatever counts wakes should look again. */ readonly onChange?: () => void; } export declare class WakeDesk { private readonly queues; private readonly iterations; private readonly send; private readonly onChange; private idle; constructor(options: WakeDeskOptions); /** How many wakes are waiting; a test reads it to see that nothing leaked. */ get size(): number; /** A loop fired: its wake waits for the next idle agent. */ record(fire: LoopFire): void; /** A loop ended while its wake waited: those wakes will never be delivered. */ cancel(taskId: string): LoopFire[]; /** A turn started, so nothing more goes out until it settles. */ busy(): void; /** The agent settled: the wakes this turn was blocking may go out now. */ settled(): Promise; /** * Deliver what an idle agent may receive, drop what may not. A wake goes out * only after its iteration binds, so the turn it wakes records its own calls; * a dropped wake takes its pending iteration with it (ADR-0009). */ flush(): Promise; /** * A queued wake still belongs to the model while its loop runs; a fire that * used the last of `maxFires` completed the loop and must still be delivered, * because that turn is the reason the count reached the limit. Every other * stopped loop drops its wake: pause, complete, expiry, delete. */ private deliverable; /** A dropped iteration is bookkeeping: a failure belongs on stderr, not in the turn. */ private safely; }