/** * Per-device-and-property command coalescing (design.md D31; task 10.12c). * * A continuous control (a brightness or position slider being dragged) must * not issue one command per intermediate value: at most one command per * device and property may be outstanding at a time, and once it settles the * latest requested value — not every intermediate one — is sent. Only the * most recent request for a key ever owns reconciliation and the D21 revert * deadline, so a confirmation for a superseded intermediate value must never * be allowed to move the control backwards. * * Pure and DOM-free (design.md D23): keyed by an opaque string (callers use * `${qualifiedId}:${property}`, keeping one device's adjustment from ever * delaying a command to another), with no dependency on React or the fetch * layer — `send` is supplied by the caller. */ /** The outcome delivered to a request's `onSettle` callback. */ export type CoalescedOutcome = { status: "sent"; result: TResult; } | { status: "sent_error"; error: unknown; } /** A later request for the same key arrived before this one was ever sent. */ | { status: "superseded"; }; /** * Coalesces requests per key so that at most one is ever in flight, with the * most recently requested value winning once the in-flight one settles. */ export declare class CommandCoalescer { private readonly send; private readonly outstandingToken; private readonly pendingByKey; constructor(send: (key: string, value: TValue) => Promise); /** * Requests that `value` be sent for `key`. * * If nothing is currently outstanding for `key`, `send` is invoked * immediately. If something is already outstanding, this call becomes the * (single) queued follow-up — superseding, and immediately notifying, any * previously queued follow-up for the same key — and is issued once the * outstanding command settles. * * `onSettle` is called exactly once: with the send outcome if this request * is the one actually issued, or synchronously with `{status: * "superseded"}` if a later call for the same key arrives before this one * is ever sent. * * Returns a token identifying this request; compare it against * {@link isLatest} before reconciling anything against a later response, * since a response can arrive after this request has already been * superseded. */ request(key: string, value: TValue, onSettle: (outcome: CoalescedOutcome) => void): symbol; /** Whether `token` is still the most recent request for `key` — in flight or queued. */ isLatest(key: string, token: symbol): boolean; /** Whether any request for `key` is currently in flight. */ isOutstanding(key: string): boolean; private issue; private advance; } /** Builds the coalescing key for a device and property, per design.md D31. */ export declare function coalescingKey(qualifiedId: string, property: string): string; //# sourceMappingURL=command-coalescing.d.ts.map