import type { AsyncEventBus, EventBus } from "./events/index.js"; import { type EventKeys, type IEvent, type IEventSink } from "./events/shared.js"; export type ResolveHandler = (value: T) => TResult | PromiseLike; export type RejectHandler = (reason: unknown) => void | TResult | PromiseLike; export { isPromiseLike } from './teardown-manager.js'; /** * Converts a Promise to an Event emitter that fires when the Promise resolves * @template T - The type of the Promise resolution value * @param {PromiseLike} promise - The Promise to convert * @returns {IEventSink<[T], void, unknown>} Event emitter that will emit the resolved value */ export declare function toEvent(promise: PromiseLike): IEventSink<[T], void, unknown>; /** * Converts an Event emitter to a Promise that resolves when the event fires * @template T - The type of the event payload * @param {IEventSink<[T], void, unknown>} event - The event emitter to convert * @returns {PromiseLike} Promise that resolves with the first event payload */ export declare function fromEvent(event: IEventSink<[T], void, unknown>): PromiseLike; /** * Converts an Event emitter to a Promise that resolves when the event fires * @template T - The type of the event payload * @param {IEventSink<[T], void, unknown>} event - The event emitter to convert * @returns {PromiseLike} Promise that resolves with the first event payload */ export declare function fromEventBus; }, T>(bus: EventBus, eventName: EventKeys): PromiseLike; /** * Converts an Event emitter to a Promise that resolves when the event fires * @template T - The type of the event payload * @param {IEventSink<[T], void, unknown>} event - The event emitter to convert * @returns {PromiseLike} Promise that resolves with the first event payload */ export declare function fromAsyncEventBus | void>; }, T>(bus: AsyncEventBus, eventName: EventKeys): Promise>; /** * A Deferred Promise pattern implementation allowing external resolution control * @template T - The type of the resolved value * @template TError - The type of the rejection reason (defaults to Error) */ export declare class Deferred implements PromiseLike { private _resolve?; private _reject?; promise: Promise; /** * Resolves the deferred Promise with a value * @param {T | PromiseLike | undefined} _value - The resolution value * @throws {Error} If called before Promise initialization */ resolve(_value?: T | PromiseLike | undefined): void; /** * Rejects the deferred Promise with a reason * @param {TError} _reason - The rejection reason * @throws {Error} If called before Promise initialization */ reject(_reason?: TError): void; constructor(); then(onfulfilled?: ((value: T) => TResult1 | PromiseLike) | undefined | null, onrejected?: ((reason: TError) => TResult2 | PromiseLike) | undefined | null): Promise; catch(onrejected?: ((reason: TError) => TResult | PromiseLike) | undefined | null): Promise; finally(onfinally?: (() => void) | undefined | null): Promise; get [Symbol.toStringTag](): string; } /** * Creates a Promise that resolves after a specified delay * @param {number} delay - Delay duration in milliseconds * @returns {Promise} Promise that resolves after the delay */ export declare function delay(delay: number): Promise; /** * Wraps a Promise with a timeout, rejecting if it doesn't resolve in time * @template T - The type of the original Promise resolution * @param {PromiseLike} promise - The Promise to wrap * @param {number} timeoutInMs - Timeout duration in milliseconds * @returns {PromiseLike} New Promise that either resolves with the original value or rejects with 'timeout' */ export declare function whenOrTimeout(promise: PromiseLike, timeoutInMs: number): PromiseLike; /** * Enum representing the possible states of a Promise * @enum {number} */ export declare enum PromiseStatus { Pending = 0, Resolved = 1, Rejected = 2 }