Wren a web browser where WebAssembly runs everything, JavaScript included

Module ports

MessagePorts between realms (src/page/ports.odin; native/js/runtime/web_message.c, workers.c): a port whose other side is in another realm (another document, a worker) talks through a pair of port ends the browser routes. An end belongs to one realm at a time; while it travels in a message it belongs to none, and what is posted to it waits for its next owner.

Exposed to: Window, Worker. Source: api/ports.widl.

Odin: import "wren:ports".

Functions

Port_entangle

u64 Port_entangle()

A new pair of entangled port ends: the first end's id (the second is that id + 1), owned by nobody yet.

Host: Port_entangle :: proc(c: ^Call) -> u64

Port_bind

void Port_bind(u64 end) raises

The calling realm owns this end from now on: what was posted to it meanwhile is delivered (each message from a task: the engine's wj_port_message). Invalid_Argument for an end that is gone or owned.

Raises: returns an Error (see web).

Host: Port_bind :: proc(c: ^Call, end: u64) -> Api_Error

Port_ship

void Port_ship(u64 end)

The calling realm gives this end up (it is in a message being sent).

Host: Port_ship :: proc(c: ^Call, end: u64)

Port_post

void Port_post(u64 end, bytes data, u64[] ports) raises

port.postMessage(message, [ports]) on an end: delivered to the other end's owner (queued while it has none). Data_Clone for a message over frames.max_message_bytes.

Raises: returns an Error (see web).

Host: Port_post :: proc(c: ^Call, end: u64, data: []u8, ports: []u64) -> Api_Error

Port_close

void Port_close(u64 end)

port.close(): the pair is disentangled; nothing more is delivered to either end.

Host: Port_close :: proc(c: ^Call, end: u64)

Worker_postSerializedPorts

void Worker_postSerializedPorts(u64 worker, bytes data, u64[] ports) raises

worker.postMessage(message, transfer) with MessagePorts in the transfer list (shipped as ports).

Raises: returns an Error (see web).

Host: Worker_postSerializedPorts :: proc(c: ^Call, worker: u64, data: []u8, ports: []u64) -> Api_Error

DedicatedWorkerGlobalScope_postSerializedPorts

void DedicatedWorkerGlobalScope_postSerializedPorts(bytes data, u64[] ports) raises

postMessage(message, transfer) in a worker, with MessagePorts.

Raises: returns an Error (see web).

Host: DedicatedWorkerGlobalScope_postSerializedPorts :: proc(c: ^Call, data: []u8, ports: []u64) -> Api_Error

Broadcast_open

u64 Broadcast_open(string name)

new BroadcastChannel(name): a port end of the channel (the realm's origin and the name), owned by the calling realm; 0 for an opaque origin (the object sends and receives nothing). Port_close closes it.

Host: Broadcast_open :: proc(c: ^Call, name: string) -> u64

Broadcast_post

void Broadcast_post(u64 end, bytes data) raises

broadcastChannel.postMessage: the serialized message to every other end of the channel, in every realm. Data_Clone for a message over frames.max_message_bytes.

Raises: returns an Error (see web).

Host: Broadcast_post :: proc(c: ^Call, end: u64, data: []u8) -> Api_Error

MessageEvent_portEnds

bytes MessageEvent_portEnds(Event event)

The port ends that came with a worker's message event (8 bytes each), given once: the caller binds them.

Host: MessageEvent_portEnds :: proc(c: ^Call, event: Api_Event) -> []u8

Edit this page on GitHub