()
| 287 | } |
| 288 | |
| 289 | #tryToStartAnother(): boolean { |
| 290 | if (this.#queue.size === 0) { |
| 291 | // We can clear the interval ("pause") |
| 292 | // Because we can redo it later ("resume") |
| 293 | this.#clearIntervalTimer(); |
| 294 | this.emit('empty'); |
| 295 | |
| 296 | if (this.#pending === 0) { |
| 297 | // Clear timeout as well when completely idle |
| 298 | this.#clearTimeoutTimer(); |
| 299 | |
| 300 | // Compact strict ticks when idle to free memory |
| 301 | if (this.#strict && this.#strictTicksStartIndex > 0) { |
| 302 | const now = Date.now(); |
| 303 | this.#cleanupStrictTicks(now); |
| 304 | } |
| 305 | |
| 306 | this.emit('idle'); |
| 307 | } |
| 308 | |
| 309 | return false; |
| 310 | } |
| 311 | |
| 312 | let taskStarted = false; |
| 313 | |
| 314 | if (!this.#isPaused) { |
| 315 | const now = Date.now(); |
| 316 | const canInitializeInterval = !this.#isIntervalPausedAt(now); |
| 317 | |
| 318 | if (this.#doesIntervalAllowAnother && this.#doesConcurrentAllowAnother) { |
| 319 | const job = this.#queue.dequeue()!; |
| 320 | |
| 321 | if (!this.#isIntervalIgnored) { |
| 322 | this.#consumeIntervalSlot(now); |
| 323 | this.#scheduleRateLimitUpdate(); |
| 324 | } |
| 325 | |
| 326 | this.emit('active'); |
| 327 | job(); |
| 328 | |
| 329 | if (canInitializeInterval) { |
| 330 | this.#initializeIntervalIfNeeded(); |
| 331 | } |
| 332 | |
| 333 | taskStarted = true; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | return taskStarted; |
| 338 | } |
| 339 | |
| 340 | #initializeIntervalIfNeeded(): void { |
| 341 | if (this.#isIntervalIgnored || this.#intervalId !== undefined) { |
no test coverage detected