Function: retry()
retry<
T>(func,options):Promise<T>
Defined in: packages/promise/src/retry.ts:69
Executes a function asynchronously and retries it on failure or until a specific condition is met.
The function will be re-executed if:
- The
funcpromise rejects or the function throws an error. - The optional
retryIffunction returnstrue. retry > 0
Retries will stop when the retry count is exhausted, or when func executes successfully (resolves without error) AND the retryIf (if provided) returns false.
Type Parameters
T
T
The type of the value that the func resolves to.
Parameters
func
() => ValueOrPromise<T>
The function to execute. It can be synchronous or asynchronous.
options
RetryOptions<T>
(optional) Configuration of the retry mechanism.
The following options' default values can be configured to be EFFECTIVE GLOBALLY.
PromisE.retry.defaults = {
retry: 1,
retryBackOff: 'exponential',
retryDelay: 300,
retryDelayJitter: true,
retryDelayJitterMax: 100,
}Returns
Promise<T>
A promise that resolves with the result of the last successful execution of func. If all retries fail (either by throwing an error or when retryIf() returned true in every time), it resolves with the last return value of func(). Errors thrown by func are caught and handled internally, only re-thrown if no result is received after maximum retries.