rvx
Version:
A signal based rendering library
18 lines (17 loc) • 1.03 kB
TypeScript
import { Expression } from "../core/signals.js";
import type { Falsy } from "../core/types.js";
export type WatchGuardCondition<T, R extends T> = (value: T) => value is R;
export type WatchCondition<T> = (value: T) => boolean;
export declare class WatchForTimeoutError extends Error {
}
/**
* Utility to watch an expression until it's output satisfies a condition.
*
* @param expr The expression to watch.
* @param condition The condition to test. By default, all truthy values are matched.
* @param timeout An optional timeout. Default is no timeout.
* @returns A promise that resolves with the first matched output or rejects with a {@link WatchForTimeoutError}.
*/
export declare function watchFor<T>(expr: Expression<T | Falsy>, timeout?: number): Promise<T>;
export declare function watchFor<T, R extends T>(expr: Expression<T>, condition?: WatchGuardCondition<T, R>, timeout?: number): Promise<R>;
export declare function watchFor<T>(expr: Expression<T>, condition?: WatchCondition<T>, timeout?: number): Promise<T>;