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

Method #updateStaleTimeout

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

Source from the content-addressed store, hash-verified

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