1 |
|
2 |
|
3 |
|
4 | import { IRetryPolicy, RetryContext } from "./IRetryPolicy";
|
5 |
|
6 |
|
7 | const DEFAULT_RETRY_DELAYS_IN_MILLISECONDS = [0, 2000, 10000, 30000, null];
|
8 |
|
9 |
|
10 | export class DefaultReconnectPolicy implements IRetryPolicy {
|
11 | private readonly retryDelays: Array<number | null>;
|
12 |
|
13 | constructor(retryDelays?: number[]) {
|
14 | this.retryDelays = retryDelays !== undefined ? [...retryDelays, null] : DEFAULT_RETRY_DELAYS_IN_MILLISECONDS;
|
15 | }
|
16 |
|
17 | public nextRetryDelayInMilliseconds(retryContext: RetryContext): number | null {
|
18 | return this.retryDelays[retryContext.previousRetryCount];
|
19 | }
|
20 | }
|