(options = {})
| 464 | } |
| 465 | |
| 466 | nextDelay(options = {}) { |
| 467 | const forceSlow = Boolean(options.forceSlow); |
| 468 | let delay = this.baseIntervalMs * this.getConnectionMultiplier(); |
| 469 | if (!api.networkOnline || forceSlow) { |
| 470 | delay = Math.max(delay, this.baseIntervalMs * 2.5); |
| 471 | } |
| 472 | if (this.failureCount > 0) { |
| 473 | delay *= Math.pow(1.55, Math.min(this.failureCount, 5)); |
| 474 | } else if (this.successCount >= 3) { |
| 475 | delay *= 0.88; |
| 476 | } |
| 477 | delay = Math.max(this.minIntervalMs, Math.min(this.maxIntervalMs, Math.round(delay))); |
| 478 | const jitter = Math.round(delay * this.jitterRatio * (Math.random() * 2 - 1)); |
| 479 | this.lastDelayMs = Math.max(this.minIntervalMs, Math.min(this.maxIntervalMs, delay + jitter)); |
| 480 | return this.lastDelayMs; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | function createAdaptivePoller(options = {}) { |
no test coverage detected