Retry - @mvdlei/retry
The retry
package provides a utility for retrying asynchronous operations with customizable options.
Installation
Example
API Reference
IRetryOptions
Options for configuring the retry behavior.
attempts
: The maximum number of retry attempts.delay
: The delay between retry attempts. It can be a number or an object withmin
,max
, anddefault
values.factor
: The exponential factor for calculating delays.minDelay
: The minimum delay between retries.maxDelay
: The maximum delay between retries.exponential
: Flag to indicate whether to use exponential backoff.forever
: Flag to retry forever until successful.randomize
: Flag to randomize the delay between retries.
Delays are in milliseconds.
Default Options
IRetry
Interface defining the retry utility.
retry<T>(fn: () => Promise<T>, options?: IRetryOptions): Promise<T>
Retry a function until it succeeds or the maximum number of attempts is reached.
fn
: The function to retry.options
: Optional retry options.
retry<T>(fn: () => Promise<T>): Promise<T>
Retry a function until it succeeds or the maximum number of attempts is reached.
fn
: The function to retry.
Default options are used, or the options provided in Retry.init()
.
Retry
Class
The Retry
class implements the IRetry
interface.
Retry.init(options?: Partial<IRetryOptions>): IRetry
Static method to initialize a new Retry
instance with the provided options.
options
: Optional retry options.