watchUntil
Watches
sourceuntilcallbackreturnstrueor another configurable value.
Usage
js
import { watchUntil } from '@8ctavio/vergil'
watchUntil(src, (v,u) => {
if (condition(v,u)){
// ...
return true // watchUntil resolves to v
}
})Definition
ts
// Single watch source
function watchUntil<T, O extends WatchUntilOptions>(
source: WatchSource<T>,
callback: WatchUntilCallback<T,O>,
options?: O
): Promise<T | undefined>
// Multiple watch sources
function watchUntil<T, O extends WatchUntilOptions>(
source: WatchSource<T>[],
callback: WatchUntilCallback<T[], O>,
options?: O
): Promise<T[] | undefined>
type WatchUntilOptions = {
fulfill?: unknown;
timeout?: number;
signal?: AbortSignal;
deep?: boolean | number;
flush?: 'pre' | 'post' | 'sync';
}
type WatchUntilCallback<T, O extends WatchUntilOptions> =
(...args: Parameters<WatchCallback<T, MaybeUndefined<T>>>) =>
| (O extends { fulfill: infer F } ? F : boolean)
| voidParameters
fulfill: The return value required to stop the watcher. Defaults totrue.timeout: Duration of watcher timeout in milliseconds. If set andcallbackis not fulfilled aftertimeoutmilliseconds, the watcher stops.signal:AbortSignalto abort watcher with a correspondingAbortController.- For others, see watch.
Return value
A promise. Resolves to the WatchSource value that fulfilled the callback. If aborted, the promise rejects with the abort signal's abort reason (signal.reason).