UNPKG

1.1 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.AdaptiveRetryStrategy = void 0;
4const util_retry_1 = require("@aws-sdk/util-retry");
5const StandardRetryStrategy_1 = require("./StandardRetryStrategy");
6class AdaptiveRetryStrategy extends StandardRetryStrategy_1.StandardRetryStrategy {
7 constructor(maxAttemptsProvider, options) {
8 const { rateLimiter, ...superOptions } = options !== null && options !== void 0 ? options : {};
9 super(maxAttemptsProvider, superOptions);
10 this.rateLimiter = rateLimiter !== null && rateLimiter !== void 0 ? rateLimiter : new util_retry_1.DefaultRateLimiter();
11 this.mode = util_retry_1.RETRY_MODES.ADAPTIVE;
12 }
13 async retry(next, args) {
14 return super.retry(next, args, {
15 beforeRequest: async () => {
16 return this.rateLimiter.getSendToken();
17 },
18 afterRequest: (response) => {
19 this.rateLimiter.updateClientSendingRate(response);
20 },
21 });
22 }
23}
24exports.AdaptiveRetryStrategy = AdaptiveRetryStrategy;