()
| 507 | } |
| 508 | |
| 509 | #updateStaleTimeout(): void { |
| 510 | this.#clearStaleTimeout() |
| 511 | const staleTime = resolveQueryValue( |
| 512 | this.options.staleTime, |
| 513 | this.#currentQuery, |
| 514 | ) |
| 515 | |
| 516 | if (this.#currentResult.isStale || !this.#shouldScheduleTimer(staleTime)) { |
| 517 | return |
| 518 | } |
| 519 | |
| 520 | const time = timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime) |
| 521 | |
| 522 | // The timeout is sometimes triggered 1 ms before the stale time expiration. |
| 523 | // To mitigate this issue we always add 1 ms to the timeout. |
| 524 | const timeout = time + 1 |
| 525 | |
| 526 | this.#staleTimeoutId = timeoutManager.setTimeout(() => { |
| 527 | if (!this.#currentResult.isStale) { |
| 528 | this.updateResult() |
| 529 | } |
| 530 | }, timeout) |
| 531 | } |
| 532 | |
| 533 | #computeRefetchInterval() { |
| 534 | return ( |
no test coverage detected