/** * @file Escalating-wait pacing for code that polls or retries against * rate-limited services: a `createBackoff` state machine — initial delay, * multiply per wait, optional cap, reset on forward progress. Unlike * `pRetry`, which owns the whole retry loop, a `Backoff` is a passive * pacing primitive the caller drives from its own loop. */ export interface BackoffOptions { factor?: number | undefined; maxMs?: number | undefined; sleeper?: ((ms: number) => Promise) | undefined; } export interface Backoff { currentMs(): number; reset(): void; wait(): Promise; } /** * Create an escalating-wait state machine starting at `ms`: `wait()` sleeps * the current delay, then multiplies it by `factor` (default 2) up to `maxMs`; * `reset()` returns to `ms` after forward progress. `sleeper` is injectable so * tests drive every wait with no real delay. * * @example * ;```ts * const backoff = createBackoff(1000, { maxMs: 30_000 }) * while (!(await poll())) { * await backoff.wait() // 1s, 2s, 4s, … capped at 30s * } * backoff.reset() // forward progress: next wait() is 1s again * ``` * * @param ms - The initial delay in milliseconds. * @param options - Optional `factor`, `maxMs`, and injectable `sleeper`. * * @returns A `Backoff` pacing state machine. */ export declare function createBackoff(ms: number, options?: BackoffOptions | undefined): Backoff;