Skip to content
1 min read · 147 words

Interface: PortLike ​

Defined in: src/batteries/isolation/types.ts:313

The minimal message-passing duck the wire protocol (protocol.ts) is built over. A Worker / MessagePort (post = postMessage, onMessage wraps addEventListener('message', ...)) and a Node ChildProcess / process (post = .send, onMessage wraps .on('message', ...)) both satisfy this structurally — the shared protocol is exercised against linked in-memory fake ports; the browser and Node transports wire it to the real transports.

Methods ​

onMessage() ​

ts
onMessage(fn: (msg: unknown) => void): () => void;

Defined in: src/batteries/isolation/types.ts:317

Subscribe to inbound messages. Returns an unsubscribe function.

Parameters ​

ParameterType
fn(msg: unknown) => void

Returns ​

() => void


post() ​

ts
post(msg: unknown): void;

Defined in: src/batteries/isolation/types.ts:315

Send a message across the port. Fire-and-forget — no delivery confirmation at this layer.

Parameters ​

ParameterType
msgunknown

Returns ​

void