()
| 852 | } |
| 853 | |
| 854 | #updateRateLimitState(): void { |
| 855 | const previous = this.#rateLimitedInInterval; |
| 856 | |
| 857 | // Early exit if rate limiting is disabled or queue is empty |
| 858 | if (this.#isIntervalIgnored || this.#queue.size === 0) { |
| 859 | if (previous) { |
| 860 | this.#rateLimitedInInterval = false; |
| 861 | this.emit('rateLimitCleared'); |
| 862 | } |
| 863 | |
| 864 | return; |
| 865 | } |
| 866 | |
| 867 | // Get the current count based on mode |
| 868 | let count: number; |
| 869 | if (this.#strict) { |
| 870 | const now = Date.now(); |
| 871 | this.#cleanupStrictTicks(now); |
| 872 | count = this.#getActiveTicksCount(); |
| 873 | } else { |
| 874 | count = this.#intervalCount; |
| 875 | } |
| 876 | |
| 877 | const shouldBeRateLimited = count >= this.#intervalCap; |
| 878 | |
| 879 | if (shouldBeRateLimited !== previous) { |
| 880 | this.#rateLimitedInInterval = shouldBeRateLimited; |
| 881 | this.emit(shouldBeRateLimited ? 'rateLimit' : 'rateLimitCleared'); |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | /** |
| 886 | Whether the queue is currently rate-limited due to intervalCap. |
no test coverage detected