MCPcopy
hub / github.com/TanStack/query / suspense

Function suspense

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

Source from the content-addressed store, hash-verified

146 }
147
148 const suspense = () => {
149 return new Promise<QueryObserverResult<TData, TError>>(
150 (resolve, reject) => {
151 let stopWatch = () => {
152 // noop
153 }
154 const run = () => {
155 if (defaultedOptions.value.enabled !== false) {
156 // fix #6133
157 observer.setOptions(defaultedOptions.value)
158 const optimisticResult = observer.getOptimisticResult(
159 defaultedOptions.value,
160 )
161 if (optimisticResult.isStale) {
162 stopWatch()
163 observer
164 .fetchOptimistic(defaultedOptions.value)
165 .then(resolve, (error: TError) => {
166 if (
167 shouldThrowError(defaultedOptions.value.throwOnError, [
168 error,
169 observer.getCurrentQuery(),
170 ])
171 ) {
172 reject(error)
173 } else {
174 resolve(observer.getCurrentResult())
175 }
176 })
177 } else {
178 stopWatch()
179 resolve(optimisticResult)
180 }
181 }
182 }
183
184 run()
185
186 stopWatch = watch(defaultedOptions, run)
187 },
188 )
189 }
190
191 // Handle error boundary
192 watch(

Callers

nothing calls this directly

Calls 1

runFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…