/** * Retries an async function with configurable attempts and delay between retries. * * @param fn - The async function to retry. * @param options - Configuration options for retry behavior. * @param options.maxAttempts - Maximum number of attempts (default: 3). * @param options.delay - Delay between retries in milliseconds (default: 1000). * @param options.backoff - Backoff strategy: 'fixed', 'linear', or 'exponential' (default: 'fixed'). * @param options.onRetry - Callback function called on each retry attempt. * @returns Promise that resolves with the successful result or rejects with the final error. * * @throws {Error} If maxAttempts is less than 1 or delay is negative. * * @example * // Basic retry with default settings * const result = await asyncRetry(async () => { * const response = await fetch('/api/data'); * if (!response.ok) throw new Error('Network error'); * return response.json(); * }); // Retries up to 3 times with 1s delay * * @example * // Custom retry configuration * const result = await asyncRetry( * async () => unstableApiCall(), * { * maxAttempts: 5, * delay: 500, * backoff: 'exponential', * onRetry: (attempt, error) => console.log(`Retry ${attempt}: ${error.message}`) * } * ); * * @example * // Linear backoff retry * const result = await asyncRetry( * async () => databaseQuery(), * { maxAttempts: 4, delay: 1000, backoff: 'linear' } * ); // Delays: 1s, 2s, 3s, 4s * * @note The function will throw the last error if all retry attempts fail. * * @complexity Time: O(n) where n is maxAttempts, Space: O(1) */ export declare function asyncRetry(fn: () => Promise, options?: { maxAttempts?: number; delay?: number; backoff?: 'fixed' | 'linear' | 'exponential'; onRetry?: (attempt: number, error: Error) => void; }): Promise; //# sourceMappingURL=asyncRetry.d.ts.map