function asyncRetry<TFn>(fn, initialOptions): (...args) => Promise<undefined | Awaited<ReturnType<TFn>>>
function asyncRetry<TFn>(fn, initialOptions): (...args) => Promise<undefined | Awaited<ReturnType<TFn>>>
Defined in: async-retryer.ts:663
Creates a retry-enabled version of an async function. This is a convenience wrapper around the AsyncRetryer class that returns the execute method.
• TFn extends AnyAsyncFunction
TFn
The async function to add retry functionality to
AsyncRetryerOptions<TFn> = {}
Configuration options for the retry behavior
Function
A new function that executes the original with retry logic
...Parameters<TFn>
Promise<undefined | Awaited<ReturnType<TFn>>>
// Define your async function normally
async function fetchData(url: string) {
const response = await fetch(url)
if (!response.ok) throw new Error('Request failed')
return response.json()
}
// Create retry-enabled function
const fetchWithRetry = asyncRetry(fetchData, {
maxAttempts: 3,
backoff: 'exponential',
baseWait: 1000,
jitter: 0.1
})
// Call it multiple times
const data1 = await fetchWithRetry('/api/data1')
const data2 = await fetchWithRetry('/api/data2')
// Define your async function normally
async function fetchData(url: string) {
const response = await fetch(url)
if (!response.ok) throw new Error('Request failed')
return response.json()
}
// Create retry-enabled function
const fetchWithRetry = asyncRetry(fetchData, {
maxAttempts: 3,
backoff: 'exponential',
baseWait: 1000,
jitter: 0.1
})
// Call it multiple times
const data1 = await fetchWithRetry('/api/data1')
const data2 = await fetchWithRetry('/api/data2')
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.
