UNPKG

@lifeart/gxt

Version:

<img align="right" width="95" height="95" alt="Philosopher’s stone, logo of PostCSS" src="./public/logo.png">

29 lines (27 loc) • 1.02 kB
import { Component } from './component'; export declare const SUSPENSE_CONTEXT: unique symbol; export type SuspenseContext = { start: () => void; end: () => void; }; /** * Track a promise within a suspense boundary. * * Calls `start()` on the nearest suspense context when invoked, * and `end()` when the promise settles (resolves or rejects). * * The promise is also registered with the destructor tree so that * component destruction waits for pending async operations. * * @param ctx - The component context to find the suspense boundary from * @param promise - The promise to track * @returns A promise that resolves/rejects with the same value as the input, * but guarantees that `end()` has been called when awaited * * @example * ```ts * const data = await followPromise(this, fetch('/api/data')); * // At this point, suspense end() has been called * ``` */ export declare function followPromise<T extends Promise<any>>(ctx: Component<any>, promise: T): Promise<Awaited<T>>;