* 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>)
| 24 | * synchronously (or resolved with `undefined`). |
| 25 | */ |
| 26 | function 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 |