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

Method #updateStaleTimeout

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

Source from the content-addressed store, hash-verified

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 (

Callers 2

setOptionsMethod · 0.95
#updateTimersMethod · 0.95

Calls 6

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

Tested by

no test coverage detected