import { Close, Connection } from './transport.js'; /** * Command/result matching over one connection. Created by * {@link openChannel}. */ export interface Channel { /** * Send `command` and resolve with the result that answers it (the opaque * payload); rejects with a reason when the channel was closed before the * result arrived. Settles exactly once, always async. */ send(command: unknown): PromiseLike; /** * The underlying connection's terminal end: a {@link PromiseLike} that * resolves with the {@link Close} that ended it, whatever its cause. The * `code` is the close registry's, so a consumer can tell one end from another * without reading the `reason`, which carries the server's own detail where * it sent one. */ readonly closed: PromiseLike; /** * Close the underlying connection (resolving {@link Channel.closed} with the * optional `reason`) and fail every in-flight command. */ close(reason?: string): void; } /** * Open a {@link Channel} over a single {@link Connection}. * * State lives in the closure: `pending` parks each command's callbacks, * oldest first, until the result that answers it arrives (or the channel * tears down). Reacting to `connection.closed` here — rather than just * forwarding it — is what tears the channel down when the *connection* ends * on its own (e.g. a refused resume), not only when the caller invokes * `close`. */ export declare function openChannel(connection: Connection): Channel;