UNPKG

2.19 kBTypeScriptView Raw
1export interface BackoffOptions {
2 initialDelay?: number;
3 multiplier?: number;
4 jitter?: number;
5 maxDelay?: number;
6}
7export declare class BackoffTimeout {
8 private callback;
9 /**
10 * The delay time at the start, and after each reset.
11 */
12 private readonly initialDelay;
13 /**
14 * The exponential backoff multiplier.
15 */
16 private readonly multiplier;
17 /**
18 * The maximum delay time
19 */
20 private readonly maxDelay;
21 /**
22 * The maximum fraction by which the delay time can randomly vary after
23 * applying the multiplier.
24 */
25 private readonly jitter;
26 /**
27 * The delay time for the next time the timer runs.
28 */
29 private nextDelay;
30 /**
31 * The handle of the underlying timer. If running is false, this value refers
32 * to an object representing a timer that has ended, but it can still be
33 * interacted with without error.
34 */
35 private timerId;
36 /**
37 * Indicates whether the timer is currently running.
38 */
39 private running;
40 /**
41 * Indicates whether the timer should keep the Node process running if no
42 * other async operation is doing so.
43 */
44 private hasRef;
45 /**
46 * The time that the currently running timer was started. Only valid if
47 * running is true.
48 */
49 private startTime;
50 constructor(callback: () => void, options?: BackoffOptions);
51 private runTimer;
52 /**
53 * Call the callback after the current amount of delay time
54 */
55 runOnce(): void;
56 /**
57 * Stop the timer. The callback will not be called until `runOnce` is called
58 * again.
59 */
60 stop(): void;
61 /**
62 * Reset the delay time to its initial value. If the timer is still running,
63 * retroactively apply that reset to the current timer.
64 */
65 reset(): void;
66 /**
67 * Check whether the timer is currently running.
68 */
69 isRunning(): boolean;
70 /**
71 * Set that while the timer is running, it should keep the Node process
72 * running.
73 */
74 ref(): void;
75 /**
76 * Set that while the timer is running, it should not keep the Node process
77 * running.
78 */
79 unref(): void;
80}