/** * vapor-chamber - pacing at the sender. * * `pace(send, { debounce })` or `pace(send, { throttle })` wraps a dispatch so * a burst of calls reaches the bus at the sender's rhythm. The bus never paces: * the input or the button knows its own rhythm. */ import { type CommandResult } from './command-bus'; import type { ResultOn } from './shared-bus'; /** How a sender paces its calls: one of the two, a wait in milliseconds. */ export type PaceOptions = { debounce: number; throttle?: undefined; } | { throttle: number; debounce?: undefined; }; /** A dispatch, as the bus and the composables hand it out: `options.signal` cancels it. */ export type Send = (action: any, target?: any, payload?: any, options?: { signal?: AbortSignal; }) => CommandResult | Promise; /** A paced dispatch: always a promise, plus `dispose()` for its timers. */ export type Paced = ((action: any, target?: any, payload?: any) => Promise) & { /** Cancel the timers and abort the runs in flight. A waiting debounced call settles with `pace:aborted:dispatch`. */ dispose(): void; }; /** * pace - a dispatch paced at the sender, keyed by action and target * (`commandKey`, objects by value). * * - `debounce: ms` runs the latest call per key once `ms` pass with no newer * one, and answers it with the real result. An earlier call of the burst * answers `pace:aborted:dispatch` and never reaches the bus. Pass what * changes on each call (the typed text) as the PAYLOAD: in the target, each * value is its own key and nothing coalesces. * - `throttle: ms` runs the first call per key at once and answers a repeat * inside `ms` with `pace:limited:dispatch` (`context.retryIn`, `wait`). * * Latest wins in both: a run of a key aborts that key's run still in flight * (`dispatch(..., { signal })`), so a stale answer settles aborted and never * lands after a newer one. `dispose()` aborts what is in flight. * * A `$` action (a reset, an undo) runs at once, unpaced. A paced call always * returns a promise, on either bus. NaN is no wait, one past the timer's * maximum the maximum. tests/pace.test.ts. * * @example * const search = pace(bus.dispatch, { debounce: 300 }); * input.addEventListener('input', async () => { * const r = await search('searchQuery', {}, input.value); * if (r.ok) render(r.value); * }); */ export declare function pace(send: Send, options: PaceOptions): Paced; /** The pace options a composable takes beside its bus: one of the two, or neither. */ export type PaceOption = { debounce?: D; throttle?: undefined; } | { throttle?: T; debounce?: undefined; }; /** What a composable's dispatch returns: a promise once paced, else the bus's own kind. */ export type PacedOn = [D] extends [number] ? Promise : [T] extends [number] ? Promise : ResultOn; /** * @internal The composables' one reader of their pace options: the options * `pace` takes, or `undefined` when neither is set (no wrapper, no read per call). */ export declare function _paceOf(options: { debounce?: number; throttle?: number; } | undefined): PaceOptions | undefined; //# sourceMappingURL=pace.d.ts.map