/** * Backoff strategies for computing delay between retry attempts. * * A `BackoffStrategy` is pure delay math: given a `BackoffContext`, it returns * how long to wait before the next attempt. Policy concerns — whether to retry, * whether to honor a server-provided `Retry-After` hint, max attempts, total * time budgets — live in the retry orchestration layer, not here. */ /** * Context passed to a {@link BackoffStrategy} for each retry decision. * * Treated as an open, additive-only contract: new optional fields may be added * over time, but existing fields will not be removed or repurposed. */ export interface BackoffContext { /** 1-based index of the attempt that just failed. Must be \>= 1. */ attempt: number; /** Total milliseconds elapsed since the first attempt started. */ elapsedMs: number; /** Previously computed delay, if any. Absent before the first retry. */ lastDelayMs?: number; } /** * Computes the delay before the next retry attempt. */ export interface BackoffStrategy { /** * Returns the delay in milliseconds before the next attempt. * * Must be a non-negative finite number. Implementations should treat * `ctx.attempt < 1` as a programmer error. */ nextDelay(ctx: BackoffContext): number; } /** * Supported jitter modes. * * - `none`: return the raw delay unchanged * - `full`: uniform random in `[0, raw]` * - `equal`: `raw/2 + uniform(0, raw/2)` (half fixed, half random) * - `decorrelated`: `uniform(baseMs, lastDelayMs * 3)`, capped at `maxMs`; * falls back to `full` on the first retry when `lastDelayMs` is unavailable * * For jitter outside these modes, implement {@link BackoffStrategy} directly. */ export type JitterKind = 'none' | 'full' | 'equal' | 'decorrelated'; /** * Options for {@link ConstantBackoff}. */ export interface ConstantBackoffOptions { /** Delay in ms returned for every retry. Default 1000. */ delayMs?: number; } /** * Constant backoff: returns the same delay for every retry. */ export declare class ConstantBackoff implements BackoffStrategy { private readonly _delayMs; constructor(opts?: ConstantBackoffOptions); nextDelay(ctx: BackoffContext): number; } /** * Options for {@link LinearBackoff}. */ export interface LinearBackoffOptions { /** Base delay in ms. Delay grows as `baseMs * attempt`. Default 1000. */ baseMs?: number; /** Upper bound applied before jitter. Default 30_000. */ maxMs?: number; /** Jitter mode. Default 'full'. */ jitter?: JitterKind; } /** * Linear backoff: delay grows as `baseMs * attempt`, capped at `maxMs`, then jittered. */ export declare class LinearBackoff implements BackoffStrategy { private readonly _baseMs; private readonly _maxMs; private readonly _jitter; constructor(opts?: LinearBackoffOptions); nextDelay(ctx: BackoffContext): number; } /** * Options for {@link ExponentialBackoff}. */ export interface ExponentialBackoffOptions { /** Base delay in ms. Delay grows as `baseMs * multiplier^(attempt-1)`. Default 1000. */ baseMs?: number; /** Upper bound applied before jitter. Default 30_000. */ maxMs?: number; /** Growth factor per attempt. Default 2. */ multiplier?: number; /** Jitter mode. Default 'full'. */ jitter?: JitterKind; } /** * Exponential backoff: delay grows as `baseMs * multiplier^(attempt-1)`, * capped at `maxMs`, then jittered. */ export declare class ExponentialBackoff implements BackoffStrategy { private readonly _baseMs; private readonly _maxMs; private readonly _multiplier; private readonly _jitter; constructor(opts?: ExponentialBackoffOptions); nextDelay(ctx: BackoffContext): number; } //# sourceMappingURL=backoff-strategy.d.ts.map