bare-ipc
Lightweight pipe-based IPC for Bare
bare-ipc — Lightweight pipe-based IPC for Bare.
npm i bare-ipcUsage
const IPC = require('bare-ipc')
const [portA, portB] = IPC.open()
const a = portA.connect()
const b = portB.connect()
a.on('data', (data) => {
// Handle data received from b
}).end('hello b')
b.on('data', (data) => {
// Handle data received from a
}).end('hello a')API
IPC
new IPC(port: IPCPort)
Source
Returns a duplex stream using the provided port. See bare-stream's Duplex (<https://github.com/holepunchto/bare-stream>) for the duplex stream API.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
port | IPCPort | — | The port to open the stream over, as returned by IPC.open(). |
incoming: Pipe
Source
The underlying bare-pipe Pipe used for reading. Read-only.
IPC.open(): [IPCPort, IPCPort]
Source
Returns a pair of connected IPCPorts for constructing the IPC duplex stream based on bare-pipe. Each port is transferable and can be sent to another thread or process before being connected.
Returns [IPCPort, IPCPort] — A pair of connected ports, one for each end of the IPC channel.
outgoing: Pipe
Source
The underlying bare-pipe Pipe used for writing. Read-only.
ref(): this
Source
Increase the reference count for the IPC to keep the event loop alive.
unref(): this
Source
Decrease the reference count for the IPC to allow the event loop to exit.
IPCPort
new IPCPort(incoming: number, outgoing: number)
Source
Constructs a port from a pair of file handles, incoming and outgoing.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
incoming | number | — | The file handle used for reading. |
outgoing | number | — | The file handle used for writing. |
connect(): IPC
Source
Returns an IPC connected to the port and marks the port as detached.
Returns IPC — An IPC duplex stream connected to the port.
detached: boolean
Source
A boolean for whether the port is detached. A port becomes detached once it is connected or transferred, and a detached port cannot be transferred again.
incoming: number
Source
The file handle used for reading. Read-only.
outgoing: number
Source
The file handle used for writing. Read-only.
bare-ipc/errors
IPCError
IPCError.ALREADY_CONNECTED(msg: string): IPCError
Source
Create the error thrown when transferring a port that has already been connected or transferred.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
msg | string | — | The error message. |
Returns IPCError — An error with code ALREADY_CONNECTED.
See also
- Bare modules — the full
bare-*catalog. - Bare runtime API — the runtime these modules extend.