js/realm/messaging

js/realm/messaging.ts

fino:realm/messaging - MessagePort, MessageChannel, MessageEvent.

Standard WHATWG messaging API. Use MessageChannel to create a pair of entangled ports for bidirectional communication between realms. MessagePort values use structured clone semantics for local channels and transport serialization for reactor and process Realm ports.

HTML channel messaging model: https://html.spec.whatwg.org/multipage/web-messaging.html#channel-messaging

Same-isolate messages use the runtime structured-clone subset documented on global structuredClone() in js/globals/encoding.ts, so functions, symbols, weak collections, streams, and objects with unsupported prototypes fail synchronously during postMessage().

Realm transport matrix:

Realm port Clone path Transfer support
Same-isolate MessagePort Runtime structured-clone subset. ArrayBuffer and MessagePort.
Reactor ThreadPort Serializer transport. ArrayBuffer and MessagePort.
Process ProcessPort Serializer transport over process realm handles. ArrayBuffer; MessagePort rejects.

A transferred MessagePort is neutered on the sender side and re-entangled for the receiver where the transport supports it. Other structured-clone transferables such as streams are not supported yet.

import { MessageChannel } from 'fino:realm/messaging';
import { Realm } from 'fino:realm';

const channel = new MessageChannel();
const realm = new Realm({
  entry: './worker.ts',
  input: channel.port1,
  output: channel.port2,
});
realm.port.postMessage({ hello: true });

Classes

class MessagePort extends EventTarget {

Re-exported from js/globals/messaging.MessagePort.

class MessageChannel {

Re-exported from js/globals/messaging.MessageChannel.

class MessageEvent extends Event {

Re-exported from js/globals/messaging.MessageEvent.