rvx
Version:
A signal based rendering library
18 lines (17 loc) • 651 B
TypeScript
import type { Falsy } from "../core/types.js";
export interface PollFn<T> {
(abort: AbortSignal): T | Falsy | Promise<T | Falsy>;
}
export declare class PollTimeoutError extends Error {
}
/**
* Repeatedly call a function until a truthy value is returned.
*
* + The function is called at most every event cycle.
* + If a timeout occurs, a {@link PollTimeoutError} is thrown and the abort signal passed to the function is aborted with the same error.
*
* @param fn The function to run.
* @param timeout An optional timeout.
* @returns The first truthy value.
*/
export declare function poll<T>(fn: PollFn<T>, timeout?: number): Promise<T>;