fn
retry
v0.0.8testedRetries a function a specified number of times with a delay between each retry
Examples
ts
const result = await retry(() => {
return fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(response => response.json())
});ts
const result = await retry(() => {
return fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(response => response.json())
}, { times: 3, delay: 1000 });Signature
ts
export async function retry<Return>(
fn: RetryFunction<Return>,
options: RetryOptions ={ ... }Type Parameters
ReturnParameters
| Parameter | Type | Description |
|---|---|---|
fn | RetryFunction<Return> | The function to retry |
options? | RetryOptions | The options for the retry |
Returns
Promise<Return>- The result of the function