1 | import { __awaiter, __extends, __generator, __rest } from "tslib";
|
2 | import { RETRY_MODES } from "./config";
|
3 | import { DefaultRateLimiter } from "./DefaultRateLimiter";
|
4 | import { StandardRetryStrategy } from "./StandardRetryStrategy";
|
5 | var AdaptiveRetryStrategy = (function (_super) {
|
6 | __extends(AdaptiveRetryStrategy, _super);
|
7 | function AdaptiveRetryStrategy(maxAttemptsProvider, options) {
|
8 | var _this = this;
|
9 | var _a = options !== null && options !== void 0 ? options : {}, rateLimiter = _a.rateLimiter, superOptions = __rest(_a, ["rateLimiter"]);
|
10 | _this = _super.call(this, maxAttemptsProvider, superOptions) || this;
|
11 | _this.rateLimiter = rateLimiter !== null && rateLimiter !== void 0 ? rateLimiter : new DefaultRateLimiter();
|
12 | _this.mode = RETRY_MODES.ADAPTIVE;
|
13 | return _this;
|
14 | }
|
15 | AdaptiveRetryStrategy.prototype.retry = function (next, args) {
|
16 | return __awaiter(this, void 0, void 0, function () {
|
17 | var _this = this;
|
18 | return __generator(this, function (_a) {
|
19 | return [2, _super.prototype.retry.call(this, next, args, {
|
20 | beforeRequest: function () { return __awaiter(_this, void 0, void 0, function () {
|
21 | return __generator(this, function (_a) {
|
22 | return [2, this.rateLimiter.getSendToken()];
|
23 | });
|
24 | }); },
|
25 | afterRequest: function (response) {
|
26 | _this.rateLimiter.updateClientSendingRate(response);
|
27 | },
|
28 | })];
|
29 | });
|
30 | });
|
31 | };
|
32 | return AdaptiveRetryStrategy;
|
33 | }(StandardRetryStrategy));
|
34 | export { AdaptiveRetryStrategy };
|