()
| 378 | } |
| 379 | |
| 380 | #updateStaleTimeout(): void { |
| 381 | this.#clearStaleTimeout() |
| 382 | const staleTime = resolveStaleTime( |
| 383 | this.options.staleTime, |
| 384 | this.#currentQuery, |
| 385 | ) |
| 386 | |
| 387 | if (this.#currentResult.isStale || !this.#shouldScheduleTimer(staleTime)) { |
| 388 | return |
| 389 | } |
| 390 | |
| 391 | const time = timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime) |
| 392 | |
| 393 | // The timeout is sometimes triggered 1 ms before the stale time expiration. |
| 394 | // To mitigate this issue we always add 1 ms to the timeout. |
| 395 | const timeout = time + 1 |
| 396 | |
| 397 | this.#staleTimeoutId = timeoutManager.setTimeout(() => { |
| 398 | if (!this.#currentResult.isStale) { |
| 399 | this.updateResult() |
| 400 | } |
| 401 | }, timeout) |
| 402 | } |
| 403 | |
| 404 | #computeRefetchInterval() { |
| 405 | return ( |
no test coverage detected