UNPKG

evnty

Version:

0-Deps, simple, fast, for browser and node js reactive anonymous event library

29 lines (28 loc) 1.4 kB
import { Callable } from './callable.js'; /** * Signal<T> is a callable construct for sending and receiving a single asynchronous value. * It implements both Promise<T> and AsyncIterable<T>, allowing it to be awaited once * or iterated over with `for await...of`. Once signaled, it resolves the pending promise. * * @template T - The type of value the signal carries. * @param abortSignal - Optional AbortSignal used to abort waiting and reject the promise. */ export declare class Signal<T> extends Callable<[T], boolean> implements Promise<T>, AsyncIterable<T> { private readonly abortSignal?; private rx?; constructor(abortSignal?: AbortSignal | undefined); get [Symbol.toStringTag](): string; /** * Returns the internal promise that resolves with the signaled value. */ get promise(): Promise<T>; /** * Waits for the next signal value or rejects if aborted. * @returns A promise resolving to the value of type T. */ next(): Promise<T>; catch<OK = never>(onrejected?: ((reason: any) => OK | PromiseLike<OK>) | null): Promise<T | OK>; finally(onfinally?: (() => void) | null): Promise<T>; then<OK = T, ERR = never>(onfulfilled?: ((value: T) => OK | PromiseLike<OK>) | null, onrejected?: ((reason: unknown) => ERR | PromiseLike<ERR>) | null): Promise<OK | ERR>; [Symbol.asyncIterator](): AsyncIterator<T, void, void>; }