Retryable promises.
This library allows to retry a promise upon error, with support for retry limit and backoff.
A bit like promise-retry but without any dependency, using the same promise constructor as the promise your function return, and with easier error handling.
Main differences for error handling are:
- if your function doesn't take a
retryparameter, all errors will trigger a retry; - you can use multiple rejection handlers in your function without
having to care about the library's internal
EPROMISERETRYerrors (if you happen to wrap theEPROMISERETRYerror, the retry handler will be bypassed).
import retryable from 'promise-retryable'
// Conditional retry
retryable(opts, retry => stuff()
.catch(err => {
if (err instanceof SomeError) {
return retry(err)
}
throw err
}))
.then(resolved, rejected)
// Retry on any error
retryable(opts, stuff)
.then(resolved, rejected)The opts object is optional and can contain:
| Name | Description | Default |
|---|---|---|
max |
Maximum number of retries, after what the promise will be rejected with the last error. | 10 |
backoff |
Time in millisecods to wait between retries (multiplicated by retry number). | 1000 |