//#region src/event/wait.d.ts /** * Wait for an event to be fired once on the target * * @example * ```ts * import { waitOnce } from '@kazupon/jts-utils' * * const target = new EventTarget() * * // wait for 'load' event * await waitOnce(target, 'load') * // do something after 'load' event is fired * * // wait for 'data' event with abort signal * const controller = new AbortController() * await waitOnce(target, 'data', controller.signal) * // do something after 'data' event is fired or abort the waiting by controller.abort() * * // wait for 'click' event with listener * await waitOnce(target, 'click', (event) => { * console.log('clicked', event) * }) * * // wait for 'submit' event with listener and abort signal * await waitOnce(target, 'submit', (event) => { * console.log('submitted', event) * }, controller.signal) * ``` * * @typeParam T - The type of the target * * @param target - The event target * @param type - The event type * @param listenerOrSignal - An optional event listener or {@link AbortSignal} to cancel waiting * @param signal - An optional {@link AbortSignal} to cancel waiting * @returns A promise that resolves when the event is fired * @throws {DOMException | unknown} when the signal is aborted */ declare function waitOnce(target: T, type: string, listenerOrSignal?: EventListener | AbortSignal, signal?: AbortSignal): Promise; /** * An options for {@link waitFor} */ interface WaitForOptions extends AddEventListenerOptions { /** * Number of times to wait for the event * * @default 1 */ times?: number; } /** * Wait for an event to be fired on the target * * @typeParam T - The type of the target * * @param _target - The event target * @param _type - The event type * @param _listenerOrOptions - An optional event listener or {@link WaitForOptions} * @param _options - An optional {@link WaitForOptions} * @throws {DOMException | unknown} when the signal is aborted */ declare function waitFor(_target: T, _type: string, _listenerOrOptions?: EventListener | WaitForOptions, _options?: WaitForOptions): Promise; //#endregion export { WaitForOptions, waitFor, waitOnce };