UNPKG

845 BPlain TextView Raw
1// Copyright (c) .NET Foundation. All rights reserved.
2// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
4import { IRetryPolicy, RetryContext } from "./IRetryPolicy";
5
6// 0, 2, 10, 30 second delays before reconnect attempts.
7const DEFAULT_RETRY_DELAYS_IN_MILLISECONDS = [0, 2000, 10000, 30000, null];
8
9/** @private */
10export 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}