@the-link/ipc
v0.3.1
Published
Local process and socket IPC adapters for The Link.
Readme
The Link IPC
Local inter-process communication adapters for The Link.
Install
npm install @the-link/ipcProcess
ProcessLink adapts an existing Node.js process IPC channel. The channel may
come from fork() or from spawn() with an ipc standard-I/O entry.
import { spawn } from "node:child_process"
import { ProcessLink } from "@the-link/ipc/process"
const child = spawn(process.execPath, ["worker.js"], {
serialization: "advanced",
stdio: ["inherit", "inherit", "inherit", "ipc"]
})
const link = new ProcessLink(child)Inside the child, the current process is the default target:
import { ProcessLink } from "@the-link/ipc/process"
const link = new ProcessLink()ProcessLink uses the serialization policy selected when the channel was
created. It does not create, terminate, or disconnect the process.
Socket
The Socket adapters communicate through a Unix domain socket on POSIX systems or a named pipe on Windows.
import { SocketServer } from "@the-link/ipc/socket-server"
const server = new SocketServer(address)
server.onConnection(link => {
link.$inbound.subscribe("sum", (left: number, right: number) => left + right)
})
await server.listen()import { SocketClient } from "@the-link/ipc/socket-client"
const client = new SocketClient(address)
await client.connect()
const total = await client.$outbound.publishFirst<number>("sum", 20, 22)
await client.disconnect()Socket publications are bidirectional and carry remote results and failures.
UTF-8 JSON bytes are used by default. Applications may replace the Socket
serialization policy through setSerialize() and setDeserialize().
POSIX sockets use mode 0600 by default. Applications remain responsible for
selecting and managing their addresses.
Streams
A ReadableStream in a publication or its result, in either direction,
travels as a reference when the application's codec carries streams (such as
The Link MessagePack): socket links hand their codec a streams option on
every message. Each connection has its own The Link Core StreamRelay, so the
chunks follow as their own small messages on the same socket and only as fast
as the receiver reads; a large stream never becomes one oversized frame.
Streams crossing a connection end with it.
Development
bun install --frozen-lockfile
bun run verifyLicense
MIT
