retry
Retry an async function when it fails
535 bytes
Usage
The retry
function runs an async function and retries it if it fails. You can specify how many times to retry, how long to wait between retries, and whether to use exponential backoff.
Options
times
is the maximum number of times to retry (default:3
)delay
is milliseconds to sleep between retriesbackoff
is a function called to calculate the delay between retries- It receives the attempt number (starting with
1
) and returns the delay in milliseconds.
- It receives the attempt number (starting with
signal
(v12.3.0+) allows you to pass anAbortController.signal
to interrupt the retry operation
Interrupting
If a signal
is passed, the retry operation can be interrupted. When the signal is aborted, retry
’s promise will reject with a DOMException
(even in Node.js) with the message This operation was aborted
and name AbortError
.