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

Function suspense

packages/vue-query/src/useBaseQuery.ts:160–201  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

158 }
159
160 const suspense = () => {
161 return new Promise<QueryObserverResult<TData, TError>>(
162 (resolve, reject) => {
163 let stopWatch = () => {
164 // noop
165 }
166 const run = () => {
167 if (defaultedOptions.value.enabled !== false) {
168 // fix #6133
169 observer.setOptions(defaultedOptions.value)
170 const optimisticResult = observer.getOptimisticResult(
171 defaultedOptions.value,
172 )
173 if (optimisticResult.isStale) {
174 stopWatch()
175 observer
176 .fetchOptimistic(defaultedOptions.value)
177 .then(resolve, (error: TError) => {
178 if (
179 shouldThrowError(defaultedOptions.value.throwOnError, [
180 error,
181 observer.getCurrentQuery(),
182 ])
183 ) {
184 reject(error)
185 } else {
186 resolve(observer.getCurrentResult())
187 }
188 })
189 } else {
190 stopWatch()
191 resolve(optimisticResult)
192 }
193 }
194 }
195
196 run()
197
198 stopWatch = watch(defaultedOptions, run)
199 },
200 )
201 }
202
203 // Handle error boundary
204 watch(

Callers

nothing calls this directly

Calls 1

runFunction · 0.70

Tested by

no test coverage detected