Simplify online/offline status management

This commit is contained in:
Fedor Indutny 2024-03-18 14:48:00 -07:00 committed by GitHub
parent b359d28771
commit 9aff86f02b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 432 additions and 335 deletions

View file

@ -15,6 +15,17 @@ export const FIBONACCI_TIMEOUTS: ReadonlyArray<number> = [
55 * SECOND,
];
export const EXTENDED_FIBONACCI_TIMEOUTS: ReadonlyArray<number> = [
...FIBONACCI_TIMEOUTS,
89 * SECOND,
144 * SECOND,
233 * SECOND,
377 * SECOND,
610 * SECOND,
987 * SECOND,
1597 * SECOND, // ~26 minutes
];
export type BackOffOptionsType = Readonly<{
jitter?: number;
@ -28,7 +39,7 @@ export class BackOff {
private count = 0;
constructor(
private readonly timeouts: ReadonlyArray<number>,
private timeouts: ReadonlyArray<number>,
private readonly options: BackOffOptionsType = {}
) {}
@ -53,7 +64,10 @@ export class BackOff {
return result;
}
public reset(): void {
public reset(newTimeouts?: ReadonlyArray<number>): void {
if (newTimeouts !== undefined) {
this.timeouts = newTimeouts;
}
this.count = 0;
}