import { Result, ResultValidErrors } from "t-result"; //#region src/retryOnError.d.ts /** Configuration options for retryOnError function. */ type RetryOptions = { /** Delay between retries in milliseconds or function returning delay */ delayBetweenRetriesMs?: number | ((retry: number) => number); /** * Function to determine if retry should happen, receives error and duration * of last attempt */ retryCondition?: (error: Error, lastAttempt: { duration: number; retry: number; }) => boolean; /** Optional ID for debug logging */ debugId?: string; /** Disable retries */ disableRetries?: boolean; /** Function to call when retry happens */ onRetry?: (error: Error, lastAttempt: { duration: number; retry: number; }) => void; }; /** * Retries a function on error with configurable retry logic. * * @example * await retryOnError( * async (ctx) => { * console.log(`Attempt ${ctx.retry + 1}`); * return await fetchData(); * }, * 3, * { delayBetweenRetriesMs: 1000 }, * ); * * @param fn - Function to retry that receives context with retry count * @param maxRetries - Maximum number of retries * @param options - Configuration options * @param retry - Internal use only * @param originalMaxRetries - Internal use only * @returns Promise resolving to the function result or rejecting with the final * error */ declare function retryOnError(fn: (ctx: { /** Current retry count, (0 for first attempt) */ retry: number; }) => Promise, maxRetries: number, options?: RetryOptions, retry?: number, originalMaxRetries?: number): Promise; /** * Retries a result function on error with configurable retry logic. * * @param fn - Function to retry that receives context with retry count * @param maxRetries - Maximum number of retries * @param options - Configuration options * @param options.delayBetweenRetriesMs * @param options.retryCondition * @param options.debugId * @param options.disableRetries * @param options.onRetry * @param __retry - Internal use only * @param __originalMaxRetries - Internal use only * @returns Promise resolving to the function result or rejecting with the final * error */ declare function retryResultOnError(fn: (ctx: { /** Current retry count, (0 for first attempt) */ retry: number; }) => Promise>, maxRetries: number, options?: { delayBetweenRetriesMs?: number | ((retry: number) => number); retryCondition?: (error: E, lastAttempt: { duration: number; retry: number; }) => boolean; debugId?: string; disableRetries?: boolean; onRetry?: (error: E, lastAttempt: { duration: number; retry: number; }) => void; }, __retry?: number, __originalMaxRetries?: number): Promise>; //#endregion export { retryOnError, retryResultOnError };