/** * Creates a future with a reader and writer. * * @returns {Object} An object containing: * - `tx` {FutureWriter}: The writer for the future. * - `rx` {FutureReader}: The reader for the future. * * @example * // Basic usage - creating a communication channel * const { tx, rx } = future(); * * const message = 'Hello world!'; * await tx.write(message); * * // first read yields the message * const value = await rx.read(); * expect(value).toBe(message); * * // subsequent reads yield null * const noValue = await rx.read(); * expect(noValue).toBeNull(); */ export declare function future(): { tx: FutureWriter; rx: FutureReader; }; export declare class FutureReader { #private; /** * Constructs a FutureReader. * * @param {Promise} promise - The promise to be read. * @throws {Error} If the provided argument is not a promise. */ constructor(promise: any); /** * Reads the value from the promise. Can only be called once. * * @returns {Promise} Resolves with the value of the promise or null if already consumed. * @throws {Error} If the promise is rejected. */ read(): Promise; then(resolve: any, reject: any): Promise; /** * Cancels the future. Not supported for FutureReader. */ cancel(): Promise; /** * Closes the reader. No resources are released in this implementation. */ close(): void; /** * Converts the reader back into a promise. * * @returns {Promise} The original promise. */ intoPromise(): any; } export declare class FutureWriter { #private; /** * Constructs a FutureWriter. * * @param {Object} deferred - A deferred object with `resolve` and `reject` methods. * @throws {Error} If the deferred object is invalid. */ constructor(deferred: any); /** * Resolves the promise with the given value. * * @param {any} value - The value to resolve the promise with. * @throws {Error} If the writer is already closed. */ write(value: any): Promise; /** * Rejects the promise with the given reason. * * @param {any} reason - The reason for rejecting the promise. * @throws {Error} If the writer is already closed. */ abort(reason: any): Promise; /** * Resolves the promise with null and closes the writer. */ close(): Promise; /** * Rejects the promise with the given error and closes the writer. * * @param {Error} error - The error to reject the promise with. */ closeWithError(error: any): Promise; /** * Converts the writer back into a promise. * * @returns {Promise} The original promise. */ intoPromise(): any; }