Function retry

Retries an async function with exponential backoff. Useful for handling transient failures in network requests, etc.

Throws an Error when retry(config) is called with a maxAttempts below 1 or NaN, or a NaN or negative initialDelayMs, backoffMultiplier or maxDelayMs.

const fetchWithRetry = retry({ maxAttempts: 3 })(fetchData);
const data = await fetchWithRetry();
  • Parameters

    Returns <T>(fn: () => Promise<T>) => () => Promise<T>

    Wrapped function that retries on failure