blob: 5709f053d7ea51d5be5763955dd525af1c8e3abe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
/*
* Used to calculate the time to wait before reconnecting to the daemon.
* It uses a linear backoff function that goes from 500ms to 3000ms.
*/
export default class ReconnectionBackoff {
private attemptValue = 0;
public attempt(handler: () => void) {
setTimeout(handler, this.getIncreasedBackoff());
}
public reset() {
this.attemptValue = 0;
}
private getIncreasedBackoff() {
if (this.attemptValue < 6) {
this.attemptValue++;
}
return this.attemptValue * 500;
}
}
|