UNPKG

padlocal-client-ts

Version:
45 lines 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RetryStrategyRule = exports.RetryStrategy = void 0; class RetryStrategy { constructor(retryDelays, maxRetry) { this._retryCount = 0; this.maxRetry = maxRetry; this._retryDelays = retryDelays; } get retryCount() { return this._retryCount; } static getStrategy(rule, maxRetry) { if (rule === RetryStrategyRule.FAST) { return new RetryStrategy(RetryStrategy.FAST_RETRY_DELAYS, maxRetry); } return new RetryStrategy(RetryStrategy.FAST_RETRY_DELAYS, maxRetry); } canRetry() { return this._retryCount < this.maxRetry; } reset() { this._retryCount = 0; } /** * @return millisecond */ nextRetryDelay() { const index = this._retryCount++; if (index < this._retryDelays.length) { return this._retryDelays[index]; } else { return this._retryDelays[this._retryDelays.length - 1]; } } } exports.RetryStrategy = RetryStrategy; // millisecond RetryStrategy.FAST_RETRY_DELAYS = [1000, 1000, 2000, 3000, 5000, 10000, 10000]; var RetryStrategyRule; (function (RetryStrategyRule) { RetryStrategyRule[RetryStrategyRule["FAST"] = 0] = "FAST"; })(RetryStrategyRule = exports.RetryStrategyRule || (exports.RetryStrategyRule = {})); //# sourceMappingURL=RetryStrategy.js.map