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 - dial_ws
net.dial_ws(url, subprotocol, on_open, on_message) -> [net, E] Result[Unit, Str]. Blocks for the lifetime of the connection; returnsOk(())on a clean close from the server,Err(reason)on dial failure, handshake failure, read error, or write error.- dial_
ws_ actor - serve_
ws - serve_
ws_ fn - Closure-based WebSocket server. Accepts a
Value::Closureas the handler. - serve_
ws_ fn_ actor net.serve_ws_fn_actor— binds the host from the environment.- serve_
ws_ fn_ actor_ on - The same server with the bind interface named outright (#719).
- serve_
ws_ fn_ auth - Closure-based WebSocket server with a pre-handshake auth
callback. Calls
auth_closure(path, headers)before completing the WS upgrade; rejects with 401 Unauthorized when the closure returnsErr(msg). Seeserve_ws_fnfor the post-handshake behaviour (identical once auth passes). - ws_
bind_ host - Bind a WebSocket server. Blocks; returns Unit on shutdown (the
process is normally killed before that).
The interface the
net.serve_ws*family binds to (#719).