foxts
Version:
Opinionated collection of common TypeScript utils by @SukkaW
13 lines (11 loc) • 915 B
TypeScript
type FalsyValue = null | undefined | false | '' | 0 | void;
type TruthyValue = object | unknown[] | symbol | Function | Exclude<number, 0> | Exclude<string, ''> | true;
type CleanupFn = () => void;
type OnCleanup = (cleanUpFn: CleanupFn) => void;
type Scheduler = (callback: () => Promise<void>, onCleanup: OnCleanup) => void | CleanupFn;
type Predicate<T extends TruthyValue> = () => T | FalsyValue | Promise<T> | Promise<FalsyValue>;
declare function waitFor<T extends TruthyValue>(predicate: Predicate<T>, scheduler: Scheduler, abortSignal?: AbortSignal | null): Promise<T>;
declare function waitFor<T extends TruthyValue>(predicate: Predicate<T>, checkInterval?: number, abortSignal?: AbortSignal | null): Promise<T>;
declare function waitFor<T extends TruthyValue>(predicate: Predicate<T>, abortSignal: AbortSignal): Promise<T>;
export { waitFor };
export type { CleanupFn, OnCleanup, Predicate, Scheduler };