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

Method #updateStaleTimeout

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

Source from the content-addressed store, hash-verified

370 }
371
372 #updateStaleTimeout(): void {
373 this.#clearStaleTimeout()
374 const staleTime = resolveStaleTime(
375 this.options.staleTime,
376 this.#currentQuery,
377 )
378
379 if (
380 environmentManager.isServer() ||
381 this.#currentResult.isStale ||
382 !isValidTimeout(staleTime)
383 ) {
384 return
385 }
386
387 const time = timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime)
388
389 // The timeout is sometimes triggered 1 ms before the stale time expiration.
390 // To mitigate this issue we always add 1 ms to the timeout.
391 const timeout = time + 1
392
393 this.#staleTimeoutId = timeoutManager.setTimeout(() => {
394 if (!this.#currentResult.isStale) {
395 this.updateResult()
396 }
397 }, timeout)
398 }
399
400 #computeRefetchInterval() {
401 return (

Callers 2

setOptionsMethod · 0.95
#updateTimersMethod · 0.95

Calls 6

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

Tested by

no test coverage detected