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