import { type Milliseconds } from '../date/date'; import { type Maybe } from '../value/maybe.type'; /** * How {@link exponentialBackoffDelay} randomizes a delay. * * - `equal`: uniform in `[d/2, d]`, so concurrent retries spread out but never retry sooner than half the delay. * - `none`: exactly `d`. */ export type ExponentialBackoffJitter = 'equal' | 'none'; export declare const DEFAULT_EXPONENTIAL_BACKOFF_INITIAL_DELAY: Milliseconds; export declare const DEFAULT_EXPONENTIAL_BACKOFF_MAX_DELAY: Milliseconds; export declare const DEFAULT_EXPONENTIAL_BACKOFF_FACTOR = 2; export interface ExponentialBackoffDelayInput { /** * The retry number: 1 for the first retry. */ readonly attempt: number; /** * The delay before the first retry. Defaults to 1 second. */ readonly initialDelay?: Maybe; /** * The longest delay. Defaults to 60 seconds. */ readonly maxDelay?: Maybe; /** * How much the delay grows per retry. Defaults to 2. */ readonly factor?: Maybe; /** * Defaults to `equal`. */ readonly jitter?: Maybe; /** * Returns a number in `[0, 1)`. Defaults to `Math.random`; a spec passes a fixed one. */ readonly random?: Maybe<() => number>; } /** * Returns how long to wait before a retry: `initialDelay * factor^(attempt - 1)`, capped at `maxDelay`, then jittered. * * @param input - The attempt number and backoff settings. * @returns The delay in whole milliseconds. * * @dbxUtil * @dbxUtilCategory promise * @dbxUtilTags promise, retry, backoff, exponential, jitter, delay, throttle * @dbxUtilRelated wait * * @example * ```ts * exponentialBackoffDelay({ attempt: 1, jitter: 'none' }); // 1000 * exponentialBackoffDelay({ attempt: 3, jitter: 'none' }); // 4000 * exponentialBackoffDelay({ attempt: 3 }); // between 2000 and 4000 * ``` */ export declare function exponentialBackoffDelay(input: ExponentialBackoffDelayInput): Milliseconds;