utils/retry
Functions
-
exponentialDelay( options = { [options.delay], [options.factor], [options.maxDelay] } ) → ( attempt: number ) => number
module:utils/retry~exponentialDelay
Creates a function that calculates exponential back-off delay. Pass it as
options.retryDelay
toretry
.Parameters
options : object
-
Properties
[ options.delay ] : number
Base delay between invocations. Defaults to 1s.
[ options.factor ] : number
How much to increase the delay. Defaults to 2x.
[ options.maxDelay ] : number
Maximum timeout. Even if higher timeout is calculated, it cannot get higher than this value. Default to 10s.
Defaults to
{}
Returns
( attempt: number ) => number
The function calculating the delay.
-
retry( callback, options = { [options.maxAttempts], [options.retryDelay], [options.signal] } ) → Promise<TResult>
module:utils/retry~retry
Tries calling the given callback until it sucessfully resolves.
If the callback fails
maxAttempts
times, the returned promise is rejected with the last error.Type parameters
TResult
The result of a successful callback invocation.
Parameters
callback : () => Promise<TResult>
The function to call until it succeeds.
options : object
Configuration options.
Properties[ options.maxAttempts ] : number
Maximum number of attempts.
[ options.retryDelay ] : ( attempt: number ) => number
The time in milliseconds between attempts. By default it implements exponential back-off policy.
[ options.signal ] : AbortSignal
The signal to abort further retries. The callback itself is not aborted automatically.
Defaults to
{}
Returns
Promise<TResult>