1 | export interface AttemptContext {
|
2 | attemptNum: number;
|
3 | attemptsRemaining: number;
|
4 | aborted: boolean;
|
5 | abort: () => void;
|
6 | }
|
7 | export declare type AttemptFunction<T> = (context: AttemptContext, options: AttemptOptions<T>) => Promise<T>;
|
8 | export declare type BeforeAttempt<T> = (context: AttemptContext, options: AttemptOptions<T>) => void;
|
9 | export declare type CalculateDelay<T> = (context: AttemptContext, options: AttemptOptions<T>) => number;
|
10 | export declare type HandleError<T> = (err: any, context: AttemptContext, options: AttemptOptions<T>) => Promise<void> | void;
|
11 | export declare type HandleTimeout<T> = (context: AttemptContext, options: AttemptOptions<T>) => Promise<T>;
|
12 | export interface AttemptOptions<T> {
|
13 | readonly delay: number;
|
14 | readonly initialDelay: number;
|
15 | readonly minDelay: number;
|
16 | readonly maxDelay: number;
|
17 | readonly factor: number;
|
18 | readonly maxAttempts: number;
|
19 | readonly timeout: number;
|
20 | readonly jitter: boolean;
|
21 | readonly initialJitter: boolean;
|
22 | readonly handleError: HandleError<T> | null;
|
23 | readonly handleTimeout: HandleTimeout<T> | null;
|
24 | readonly beforeAttempt: BeforeAttempt<T> | null;
|
25 | readonly calculateDelay: CalculateDelay<T> | null;
|
26 | }
|
27 | export declare type PartialAttemptOptions<T> = {
|
28 | readonly [P in keyof AttemptOptions<T>]?: AttemptOptions<T>[P];
|
29 | };
|
30 | export declare function sleep(delay: number): Promise<unknown>;
|
31 | export declare function defaultCalculateDelay<T>(context: AttemptContext, options: AttemptOptions<T>): number;
|
32 | export declare function retry<T>(attemptFunc: AttemptFunction<T>, attemptOptions?: PartialAttemptOptions<T>): Promise<T>;
|