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

Method #updateStaleTimeout

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

Source from the content-addressed store, hash-verified

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 (

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