UNPKG

@stryke/capnp

Version:

A package to assist in running the Cap'n Proto compiler and creating Cap'n Proto serialization protocol schemas.

73 lines (72 loc) 2.24 kB
import { c as Deferred, g as Message$1, o as Conn } from "./capnp-es.BHkXHvyK-CQWXOqvU.cjs"; import { a as DeferredTransport } from "./index-63Za7yNc.cjs"; import { MessagePort } from "node:worker_threads"; //#region src/rpc-helpers.d.ts /** * A transport class for Cap'n Proto RPC that uses {@link MessageChannel} for communication. */ declare class CapnpRPCMessageChannelTransport extends DeferredTransport { port: MessagePort; constructor(port: MessagePort); /** * Closes the transport and removes all event listeners. */ close: () => void; /** * Sends a Cap'n Proto RPC message over the MessagePort. * * @param msg - The RPC message to send. */ sendMessage(msg: Message$1): void; } /** * A class that manages Cap'n Proto RPC connections. */ declare class CapnpRPC { /** * A queue for deferred connections that are waiting to be accepted. * * @remarks * This is used to manage incoming connections when the accept method is called. */ protected acceptQueue: Deferred<Conn>[]; /** * A map of connections by their ID. * * @remarks * This is used to manage multiple connections and allows for easy retrieval by ID. */ protected connections: Record<number, Conn>; /** * A queue for connections that are waiting to be accepted. * * @remarks * This is used to manage incoming connections when the accept method is called. */ protected connectQueue: MessagePort[]; /** * Creates a new {@link Conn} instance. * * @remarks * This class is used to manage connections and accept incoming connections using the {@link MessageChannel} API. */ connect(id?: number): Conn; /** * Accepts a connection from the connect queue. * * @returns A promise that resolves to a Conn instance when a connection is accepted. * @throws If no connections are available in the connect queue. */ accept(): Promise<Conn>; /** * Closes all connections and clears the queues. * * @remarks * This method will reject all pending accept promises and close all * connections in the connect queue. */ close(): void; } //#endregion export { CapnpRPC, CapnpRPCMessageChannelTransport }; //# sourceMappingURL=rpc-helpers.d.cts.map