API reference@evolu/commonWorker › MessagePort

Defined in: packages/common/src/Worker.ts:46

Platform-agnostic MessagePort.

Note: There is no reliable way to detect when a port is closed or disconnected. Calling postMessage on a disposed port does not throw — it silently fails. To detect dead ports, use a heartbeat pattern where the other end periodically sends "alive" messages and stale ports are pruned after a timeout.

See

https://developer.mozilla.org/en-US/docs/Web/API/MessagePort

Extends

Extended by

Methods

[dispose]()

dispose: void;

Defined in: node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.esnext.disposable.d.ts:36

Inherited from

Disposable.[dispose]

Properties

native

readonly native: NativeMessagePort<Input, Output>;

Defined in: packages/common/src/Worker.ts:72

The native underlying port for transferring via postMessage.

Example

sharedWorker.port.postMessage(
  { type: "InitConsole", port: consoleChannel.port1.native },
  [consoleChannel.port1.native],
);

onMessage

onMessage: ((message: Output) => void) | null;

Defined in: packages/common/src/Worker.ts:58

Handler for incoming messages. Messages are queued until this is assigned, matching native MessagePort behavior where setting onmessage implicitly calls start(). This enables safe async initialization — the sender can post messages immediately while the receiver sets up.


postMessage

readonly postMessage: (message: Input, transfer?: readonly Transferable[]) => void;

Defined in: packages/common/src/Worker.ts:47