rvx
Version:
A signal based rendering library
55 lines (54 loc) • 1.65 kB
TypeScript
import { Context } from "../core/context.js";
export interface AsyncContextParent {
/**
* Called by async contexts to track a pending task.
*/
track(task: Promise<unknown>): void;
}
/**
* Represents pending operations in an asynchronously rendered tree.
*
* This can be used to wait until an entire async tree is rendered or to check if any unhandled errors occurred.
*/
export declare class AsyncContext {
#private;
constructor(parent?: AsyncContextParent);
/**
* Reactively check if there are any pending tasks in this context.
*
* @example
* ```tsx
* <Show when={() => asyncCtx.pending}>
* <div class="overlay">Please wait...</div>
* </Show>
* ```
*/
get pending(): boolean;
/**
* Track the specified task in this and all parent contexts.
*/
track(task: Promise<unknown>): void;
/**
* Wait until all tracked tasks in this and all child contexts have completed.
*
* This also includes new tasks that are tracked while waiting.
*
* @throws Errors thrown by any tracked task or an {@link AsyncError} if multiple tasks failed.
*/
complete(): Promise<void>;
/**
* Create a new async context using the current context as parent.
*/
static fork(): AsyncContext;
}
/**
* Thrown by {@link AsyncContext.complete} if multiple unhandled {@link errors} occurred.
*/
export declare class AsyncError extends Error {
errors: unknown[];
constructor(errors: unknown[]);
}
/**
* Context for the current {@link AsyncContext}.
*/
export declare const ASYNC: Context<AsyncContext | undefined>;