Expand description
WebSocket server + chat-broadcast registry.
net.serve_ws(port, on_message) blocks on a TCP listener, upgrades
each incoming connection to WebSocket, and runs a per-connection
worker thread that polls both inbound (calls Lex’s on_message)
and outbound (drains broadcasts from a channel into the socket).
chat.broadcast(room, body) looks up every connection in room
and pushes body onto its outbound channel. chat.send(conn_id, body) is the same but to a single connection.
The registry is an Arc<Mutex<…>> because Lex’s immutability means
shared mutable state has to live in the host runtime. Lex code
stays pure: it receives an event, returns Nil, and any side
effects go through chat.* which is gated by the policy.
Structs§
- Chat
Registry - Global chat registry. One per
net.serve_wsinvocation.
Functions§
- chat_
broadcast chat.broadcast(room, body)— looked up at runtime by the effect handler; called from inside the Lex VM.- chat_
send - serve_
ws - Bind a WebSocket server. Blocks; returns Unit on shutdown (the process is normally killed before that).
- serve_
ws_ fn - Closure-based WebSocket server. Accepts a
Value::Closureas the handler.