R
fn

retry

v0.0.8tested

Retries 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

Return

Parameters

ParameterTypeDescription
fnRetryFunction<Return>The function to retry
options?RetryOptionsThe options for the retry

Returns

Promise<Return>- The result of the function