SKarajic /
LoLNode
| 1 | View Code Duplication | var RateLimiter = /** @class */ (function () { |
|
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
| 2 | function RateLimiter(rateLimits) { |
||
| 3 | this.rateLimits = rateLimits; |
||
| 4 | } |
||
| 5 | RateLimiter.prototype.call = function (callback) { |
||
| 6 | this.rateLimits.forEach(function (rateLimit) { |
||
| 7 | if (!rateLimit.isActive()) { |
||
| 8 | rateLimit.startTimer(); |
||
| 9 | } |
||
| 10 | if (rateLimit.getCallsLeft() > 0) { |
||
| 11 | rateLimit.decrementCall(); |
||
| 12 | callback(); |
||
| 13 | } |
||
| 14 | }); |
||
| 15 | }; |
||
| 16 | RateLimiter.prototype.isActive = function () { |
||
| 17 | var active = []; |
||
| 18 | this.rateLimits.forEach(function (rateLimit) { |
||
| 19 | active.push(rateLimit.isActive()); |
||
| 20 | }); |
||
| 21 | return active; |
||
| 22 | }; |
||
| 23 | RateLimiter.prototype.callsLeft = function () { |
||
| 24 | var active = []; |
||
| 25 | this.rateLimits.forEach(function (rateLimit) { |
||
| 26 | active.push(rateLimit.getCallsLeft()); |
||
| 27 | }); |
||
| 28 | return active; |
||
| 29 | }; |
||
| 30 | RateLimiter.prototype.timeLeft = function () { |
||
| 31 | var active = []; |
||
| 32 | this.rateLimits.forEach(function (rateLimit) { |
||
| 33 | active.push(rateLimit.getTimeLeft()); |
||
| 34 | }); |
||
| 35 | return active; |
||
| 36 | }; |
||
| 37 | return RateLimiter; |
||
| 38 | }()); |
||
| 39 | export { RateLimiter }; |
||
| 40 | //# sourceMappingURL=ratelimiter.js.map |