1 | View Code Duplication | "use strict"; |
|
0 ignored issues
–
show
Duplication
introduced
by
![]() |
|||
2 | Object.defineProperty(exports, "__esModule", { value: true }); |
||
3 | var RateLimit = /** @class */ (function () { |
||
4 | function RateLimit(calls, time, callsLeft, timeLeft) { |
||
5 | if (callsLeft === void 0) { callsLeft = calls; } |
||
0 ignored issues
–
show
|
|||
6 | if (timeLeft === void 0) { timeLeft = time; } |
||
0 ignored issues
–
show
|
|||
7 | this.originCalls = calls; |
||
8 | this.originTime = time; |
||
9 | this.currentCalls = callsLeft; |
||
10 | this.currentTime = timeLeft; |
||
11 | this.active = false; |
||
12 | } |
||
13 | RateLimit.prototype.reset = function () { |
||
14 | this.currentCalls = this.originCalls; |
||
15 | this.currentTime = this.originTime; |
||
16 | }; |
||
17 | RateLimit.prototype.decrementCall = function () { this.currentCalls--; }; |
||
18 | RateLimit.prototype.decrementTime = function () { this.currentTime--; }; |
||
19 | RateLimit.prototype.getOriginalCalls = function () { return this.originCalls; }; |
||
20 | RateLimit.prototype.getOriginalTime = function () { return this.originTime; }; |
||
21 | RateLimit.prototype.getCallsLeft = function () { return this.currentCalls; }; |
||
22 | RateLimit.prototype.getTimeLeft = function () { return this.currentTime; }; |
||
23 | RateLimit.prototype.isActive = function () { return this.active; }; |
||
24 | RateLimit.prototype.setActive = function (active) { |
||
25 | this.active = active; |
||
26 | }; |
||
27 | RateLimit.prototype.startTimer = function () { |
||
28 | var _this = this; |
||
29 | this.setActive(true); |
||
30 | this.timer = setInterval(function () { |
||
31 | _this.decrementTime(); |
||
32 | if (_this.getTimeLeft() <= 0) { |
||
33 | _this.breakTimer(); |
||
34 | } |
||
35 | }, 1000); |
||
36 | }; |
||
37 | RateLimit.prototype.breakTimer = function () { |
||
38 | this.reset(); |
||
39 | this.setActive(false); |
||
40 | clearInterval(this.timer); |
||
41 | }; |
||
42 | RateLimit.prototype.restartTimer = function () { |
||
43 | this.breakTimer(); |
||
44 | this.startTimer(); |
||
45 | }; |
||
46 | return RateLimit; |
||
47 | }()); |
||
48 | exports.RateLimit = RateLimit; |
||
49 | //# sourceMappingURL=ratelimit.js.map |