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

Function tryResolveSync

packages/query-core/src/hydration.ts:26–43  ·  view source on GitHub ↗

* Reads the value of a promise synchronously if it has already resolved, e.g. a thenable that * resolves within its `then` call. * @param promise - The promise to read. * @returns An object with the resolved `data`, or `undefined` if the promise hasn't resolved * synchronously (or resolved with

(promise: PromiseLike<unknown>)

Source from the content-addressed store, hash-verified

24 * synchronously (or resolved with `undefined`).
25 */
26function tryResolveSync(promise: PromiseLike<unknown>) {
27 let data: unknown
28
29 const thenResult = promise.then((result) => {
30 data = result
31 return result
32 }, noop) as Promise<unknown> | undefined
33
34 // .catch can be unavailable on certain kinds of thenable's
35 // oxlint-disable-next-line typescript/no-unnecessary-condition
36 thenResult?.catch?.(noop)
37
38 if (data !== undefined) {
39 return { data }
40 }
41
42 return undefined
43}
44
45/**
46 * Options for `dehydrate`, controlling which queries/mutations are included in the resulting `DehydratedState` and

Callers 1

hydrateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected