MCPcopy Create free account
hub / github.com/TanStack/query / setTimeoutProvider

Method setTimeoutProvider

packages/query-core/src/timeoutManager.ts:118–145  ·  view source on GitHub ↗

* `setTimeoutProvider` can be used to set a custom implementation of the * `setTimeout`, `clearTimeout`, `setInterval`, `clearInterval` functions, * called a `TimeoutProvider`. * * This may be useful if you notice event loop performance issues with * thousands of queries. A custom Tim

(
    provider: TimeoutProvider<TTimerId>,
  )

Source from the content-addressed store, hash-verified

116 * ```
117 */
118 setTimeoutProvider<TTimerId extends ManagedTimerId>(
119 provider: TimeoutProvider<TTimerId>,
120 ): void {
121 if (process.env.NODE_ENV !== 'production') {
122 if (this.#providerCalled && provider !== this.#provider) {
123 // After changing providers, `clearTimeout` will not work as expected for
124 // timeouts from the previous provider.
125 //
126 // Since they may allocate the same timeout ID, clearTimeout may cancel an
127 // arbitrary different timeout, or unexpected no-op.
128 //
129 // We could protect against this by mixing the timeout ID bits
130 // deterministically with some per-provider bits.
131 //
132 // We could internally queue `setTimeout` calls to `TimeoutManager` until
133 // some API call to set the initial provider.
134 console.error(
135 `[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`,
136 { previous: this.#provider, provider },
137 )
138 }
139 }
140
141 this.#provider = provider
142 if (process.env.NODE_ENV !== 'production') {
143 this.#providerCalled = false
144 }
145 }
146
147 /**
148 * `setTimeout` schedules a callback to run after approximately `delay`

Callers 3

removable.test.tsxFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected