withRetry
withRetry<
T>(fn,options):Promise<T>
Defined in: utils/timing.ts:193
Execute an async function with retry logic.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”() => Promise<T>
Async function to execute
options
Section titled “options”RetryOptions = {}
Retry options
Returns
Section titled “Returns”Promise<T>
Promise that resolves with the function result or rejects after all retries exhausted
Example
Section titled “Example”// Basic retry with defaults (3 retries, exponential backoff)const result = await withRetry(() => unreliableApi());
// Custom retry configurationconst result = await withRetry( () => fetchWithErrors(), { maxRetries: 5, delay: 500, backoff: "exponential", shouldRetry: (error) => error.status === 429 || error.status >= 500, onRetry: (error, attempt, delay) => { console.log(`Retry ${attempt} after ${delay}ms`); } });