Retries an asynchronous function using exponential backoff between attempts.
This is useful for handling transient failures, especially in network or API calls, by progressively increasing the delay between retries.
The type of the resolved value from the async function.
The asynchronous function to retry.
Optional configuration for retries, delay, and backoff factor.
A promise resolving to the function's result, or rejecting after all retries fail.
let attempt = 0;const result = await retryBackoff(async () => { if (attempt++ < 2) throw new Error("Failed"); return "Success";}, { retries: 5, baseDelay: 100, factor: 2 });console.log(result); // "Success" Copy
let attempt = 0;const result = await retryBackoff(async () => { if (attempt++ < 2) throw new Error("Failed"); return "Success";}, { retries: 5, baseDelay: 100, factor: 2 });console.log(result); // "Success"
Will throw the last encountered error after exhausting all retries.
1.1.0
Retries an asynchronous function using exponential backoff between attempts.
This is useful for handling transient failures, especially in network or API calls, by progressively increasing the delay between retries.