MCPcopy Create free account
hub / github.com/TanStack/query / #updateStaleTimeout

Method #updateStaleTimeout

packages/query-core/src/queryObserver.ts:487–509  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

485 }
486
487 #updateStaleTimeout(): void {
488 this.#clearStaleTimeout()
489 const staleTime = resolveQueryValue(
490 this.options.staleTime,
491 this.#currentQuery,
492 )
493
494 if (this.#currentResult.isStale || !this.#shouldScheduleTimer(staleTime)) {
495 return
496 }
497
498 const time = timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime)
499
500 // The timeout is sometimes triggered 1 ms before the stale time expiration.
501 // To mitigate this issue we always add 1 ms to the timeout.
502 const timeout = time + 1
503
504 this.#staleTimeoutId = timeoutManager.setTimeout(() => {
505 if (!this.#currentResult.isStale) {
506 this.updateResult()
507 }
508 }, timeout)
509 }
510
511 #computeRefetchInterval() {
512 return (

Callers 2

setOptionsMethod · 0.95
#updateTimersMethod · 0.95

Calls 6

#clearStaleTimeoutMethod · 0.95
#shouldScheduleTimerMethod · 0.95
updateResultMethod · 0.95
resolveQueryValueFunction · 0.90
timeUntilStaleFunction · 0.90
setTimeoutMethod · 0.80

Tested by

no test coverage detected