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

Method #updateStaleTimeout

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

Source from the content-addressed store, hash-verified

377 }
378
379 #updateStaleTimeout(): void {
380 this.#clearStaleTimeout()
381 const staleTime = resolveQueryValue(
382 this.options.staleTime,
383 this.#currentQuery,
384 )
385
386 if (this.#currentResult.isStale || !this.#shouldScheduleTimer(staleTime)) {
387 return
388 }
389
390 const time = timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime)
391
392 // The timeout is sometimes triggered 1 ms before the stale time expiration.
393 // To mitigate this issue we always add 1 ms to the timeout.
394 const timeout = time + 1
395
396 this.#staleTimeoutId = timeoutManager.setTimeout(() => {
397 if (!this.#currentResult.isStale) {
398 this.updateResult()
399 }
400 }, timeout)
401 }
402
403 #computeRefetchInterval() {
404 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