UNPKG

2.49 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 /**
51 * The approximate time that the currently running timer will end. Only valid
52 * if running is true.
53 */
54 private endTime;
55 constructor(callback: () => void, options?: BackoffOptions);
56 private runTimer;
57 /**
58 * Call the callback after the current amount of delay time
59 */
60 runOnce(): void;
61 /**
62 * Stop the timer. The callback will not be called until `runOnce` is called
63 * again.
64 */
65 stop(): void;
66 /**
67 * Reset the delay time to its initial value. If the timer is still running,
68 * retroactively apply that reset to the current timer.
69 */
70 reset(): void;
71 /**
72 * Check whether the timer is currently running.
73 */
74 isRunning(): boolean;
75 /**
76 * Set that while the timer is running, it should keep the Node process
77 * running.
78 */
79 ref(): void;
80 /**
81 * Set that while the timer is running, it should not keep the Node process
82 * running.
83 */
84 unref(): void;
85 /**
86 * Get the approximate timestamp of when the timer will fire. Only valid if
87 * this.isRunning() is true.
88 */
89 getEndTime(): Date;
90}