/** * Configuration options for exponential backoff. */ export interface BackoffOptions { /** * Initial delay in milliseconds before the first retry. * @default 1000 */ initialDelayMs?: number; /** * Maximum delay in milliseconds between retries. * @default 30000 */ maxDelayMs?: number; /** * Multiplier applied to the delay after each retry. * @default 2 */ multiplier?: number; /** * Maximum number of retry attempts. Use -1 for unlimited. * @default -1 */ maxAttempts?: number; /** * Optional jitter factor (0-1) to add randomness to delays. * @default 0.1 */ jitterFactor?: number; } /** * Default backoff configuration values. */ export declare const DEFAULT_BACKOFF_OPTIONS: Required; /** * Implements exponential backoff with jitter for retry scenarios. * * @example * ```typescript * const backoff = new ExponentialBackoff({ initialDelayMs: 1000, maxDelayMs: 30000 }); * * while (shouldRetry) { * try { * await doSomething(); * backoff.reset(); * break; * } catch (err) { * if (!backoff.canRetry()) throw err; * await backoff.wait(); * } * } * ``` */ export declare class ExponentialBackoff { private readonly _initialDelayMs; private readonly _maxDelayMs; private readonly _multiplier; private readonly _maxAttempts; private readonly _jitterFactor; private _currentDelayMs; private _attemptCount; constructor(options?: BackoffOptions); /** * Gets the current attempt count. */ get attemptCount(): number; /** * Gets the current delay in milliseconds (before jitter is applied). */ get currentDelayMs(): number; /** * Checks if another retry attempt is allowed. */ canRetry(): boolean; /** * Calculates the next delay with optional jitter. */ private _calculateDelayWithJitter; /** * Waits for the current backoff delay, then increments the attempt count * and calculates the next delay. * * @returns Promise that resolves after the delay. */ wait(): Promise; /** * Gets the next delay without waiting or incrementing the counter. */ peekNextDelay(): number; /** * Resets the backoff state to initial values. * Call this after a successful operation. */ reset(): void; } /** * Creates a promise that resolves after the specified delay. * * @param ms Delay in milliseconds. * @returns Promise that resolves after the delay. */ export declare function sleep(ms: number): Promise; /** * Waits for a promise to resolve with a timeout. * * @param promise The promise to wait for. * @param timeoutMs Maximum time to wait in milliseconds. * @param timeoutMessage Optional message for the timeout error. * @returns The resolved value or rejects with a timeout error. */ export declare function withTimeout(promise: Promise, timeoutMs: number, timeoutMessage?: string): Promise;