import { RxBatch } from './batch.ts'; import { RxGuard, TxGuard } from './guards.ts'; /** * Tachyon SPSC IPC bus. * * Start the consumer first, it owns the UNIX socket and the SHM arena. * All blocking operations (listen, acquireRx, drainBatch) spin then park on a futex; * call them from a Worker thread to avoid saturating the main event loop. * * `using` closes the bus automatically. * * @example * ```ts * // consumer (start first) * using bus = Bus.listen('/tmp/demo.sock', 1 << 16); * const { data, typeId } = bus.recv(); * * // producer * using bus = Bus.connect('/tmp/demo.sock'); * bus.send(Buffer.from('hello'), 1); * ``` */ export declare class Bus implements Disposable { #private; private constructor(); /** * Creates the SHM arena and waits for one producer to connect. * Blocks until the producer calls {@link connect} on the same path. * * @param socketPath Socket path * @param capacity Must be a strictly positive power of two. */ static listen(socketPath: string, capacity: number): Bus; /** * Connects to an existing SHM arena via the UNIX socket at `socketPath`. * * @throws {AbiMismatchError} If producer and consumer were compiled with incompatible versions. */ static connect(socketPath: string): Bus; /** * Signals that the consumer will never sleep. The producer skips the seq_cst fence * and consumer_sleeping check on every flush. Use only on a dedicated SCHED_FIFO thread. * Call immediately after listen/connect, before the first message. */ setPollingMode(spinMode: 0 | 1): void; /** * Binds the SHM pages to a specific NUMA node (MPOL_PREFERRED + MPOL_MF_MOVE). * No-op on non-Linux platforms. Call immediately after listen/connect. */ setNumaNode(nodeId: number): void; /** Publishes all pending unflushed TX messages to the consumer. */ flush(): void; /** Copies `data` into the ring buffer, commits, and flushes. */ send(data: Buffer | Uint8Array, typeId?: number): void; /** * Blocks until a message is available, copies the payload, and returns it. * Retries transparently on EINTR. * * @throws {PeerDeadError} If the bus has transitioned to TACHYON_STATE_FATAL_ERROR. */ recv(spinThreshold?: number): { data: Buffer; typeId: number; }; /** * Acquires an exclusive TX slot of `maxSize` bytes. * Write into the slot via {@link TxGuard.bytes}, then commit or rollback. * * @throws {TachyonError} code `ERR_TACHYON_FULL` if the ring buffer is full. */ acquireTx(maxSize: number): TxGuard; /** * Blocks until a message is available and returns a zero-copy read lease. * Returns `null` on EINTR caller decides whether to retry. * * @throws {PeerDeadError} If the bus has transitioned to TACHYON_STATE_FATAL_ERROR. */ acquireRx(spinThreshold?: number): RxGuard | null; /** * Blocks until at least one message is available, then drains up to `maxMsgs` * in a single native call. One native crossing amortizes per-message FFI cost. * * @throws {PeerDeadError} If the bus has transitioned to TACHYON_STATE_FATAL_ERROR. */ drainBatch(maxMsgs: number, spinThreshold?: number): RxBatch; /** Closes the bus and unmaps shared memory. Safe to call multiple times. */ close(): void; /** Called automatically by the `using` keyword. */ [Symbol.dispose](): void; } //# sourceMappingURL=bus.d.ts.map