import { Func } from '../types.ts'; /** * Error thrown when the maximum number of retries is reached. */ export declare class RetryError extends Error { constructor(message: string); } export declare const isRetryError: (error: unknown) => error is RetryError; export interface RetryOptions { /** * Number of retries * * @default 3 */ retries?: number; /** * Delay between retries * * @default 0 */ delay?: number; /** * Multiplier for the delay between retries * * @default 1 */ backoff?: number; /** * Jitter factor for the delay between retries * * @default 0 */ jitterFactor?: number; /** * Function to determine if the function should be retried * * @param error error to check * @returns true if the function should be retried */ shouldRetry?: (error: Error) => boolean; /** * Abort signal to cancel the retry */ signal?: AbortSignal; /** * Throw the last error encountered if all retries fail * * @default false */ throwLastError?: boolean; /** * Callback invoked before each retry attempt * * @param error last error encountered * @param attempt current attempt number */ onRetry?: (error: Error, attempt: number) => void | Promise; /** * Callback invoked after all retry attempts have been exhausted. * Use to take over error handling and return a fallback value. * * @param error last error encountered * @param args original function arguments * @returns fallback value */ onRetryExhausted?: (error: Error) => ReturnType | Promise>; } /** * Retries a function until it succeeds or the number of retries is reached. * @param fn function to retry * @param opts options * @returns * * @example * * const fetchData = retry( * async () => { * const response = await fetch('https://api.example.com/data'); * return response.json(); * }, * { * retries: 3, * delay: 1000, * backoff: 2, * shouldRetry: (error) => error.message.includes('500') * } * ); * * const data = await fetchData(); * */ export declare const retry: (fn: T, opts: RetryOptions) => Promise>; /** * Makes a function retryable. * @param fn function to make retryable * @param opts options * @returns retryable function */ export declare const makeRetryable: (fn: T, opts: RetryOptions) => T;