Function: retry()
ts
function retry<T>(factory, options?): Promise<T>;Retries an async factory on failure.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
factory | () => Promise<T> |
options | RetryOptions |
Returns
Promise<T>
Example
ts
let attempts = 0
const result = await retry(async () => {
attempts++
if (attempts < 3) throw new Error('not yet')
return 'success'
}, { times: 3, delay: 0 })
result // => 'success'
attempts // => 3Since
1.0.0