/** * Budget-capped retry utility with exponential backoff and jitter. * * Design influences: * - p-retry API (shouldRetry predicate, onRetry callback) * - Orleans ExponentialBackoff (min + step × 2^attempt, jitter) * - .NET RateLimiting (budget-based, not just count-based) */ export interface RetryOptions { /** Maximum number of retries after the initial attempt (default: 5). */ maxRetries?: number; /** * Total time budget in ms for all attempts including delays. * When exceeded, the next retry is skipped and the last error thrown. * Default: no budget (count-based only). */ budgetMs?: number; /** Base delay in ms for backoff calculation (default: 10_000). */ baseDelayMs?: number; /** Maximum delay in ms between retries (default: 60_000). */ maxDelayMs?: number; /** * Predicate that determines whether an error is retryable. */ shouldRetry: (error: unknown) => boolean; /** * Called before each retry delay. Return value is ignored. * Useful for logging retry progress. */ onRetry?: (info: RetryInfo) => void | Promise; } export interface RetryInfo { /** The error that triggered this retry. */ error: unknown; /** 1-based attempt number (1 = first retry, 2 = second retry, ...). */ attempt: number; /** Delay in ms before this retry starts. */ delayMs: number; /** Time remaining in the budget (undefined if no budget set). */ budgetRemainingMs?: number; } /** * Execute a function with automatic retries on failure. * * Retries use exponential backoff with ±50% symmetric jitter: * delay = baseDelay × 2^(attempt-1), capped at maxDelay * * Retry stops when: * - The function succeeds * - maxRetries is exhausted * - budgetMs is exceeded * - shouldRetry returns false */ export declare function withRetry(fn: () => Promise, options: RetryOptions): Promise; //# sourceMappingURL=retry.d.ts.map