UNPKG

@stryke/capnp

Version:

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

43 lines (40 loc) 1.34 kB
import { Deferred, Conn, DeferredTransport } from 'capnp-es'; import { Message } from 'capnp-es/capnp/rpc'; import { MessagePort } from 'node:worker_threads'; /** * A class that manages Cap'n Proto RPC connections. */ declare class CapnpRPC { protected acceptQueue: Deferred<Conn>[]; protected connections: Record<number, Conn>; 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; } declare class MessageChannelTransport extends DeferredTransport { port: MessagePort; constructor(port: MessagePort); close: () => void; sendMessage(msg: Message): void; } export { CapnpRPC, MessageChannelTransport };