WebSocket
represents an active WebSocket connection.
Handlers receive a reference to this and call WebSocket.send or
WebSocket.send-binary to queue outgoing text or binary
frames. The event loop drains the outbox after the handler returns.
encode-binary
(Fn [(Ref (Array Byte) a)] (Array Byte))
(encode-binary data)
encodes a byte array as a WebSocket binary frame (no mask).
encode-ping
(Fn [(Ref (Array Byte) a)] (Array Byte))
(encode-ping payload)
encodes a WebSocket ping frame with the given payload (may be empty).
encode-text
(Fn [(Ref String a)] (Array Byte))
(encode-text msg)
encodes a string as a WebSocket text frame (no mask).
outbox
(Fn [(Ref WebSocket a)] (Ref (Array (Array Byte)) a))
gets the outbox property of a WebSocket.
send
(Fn [(Ref WebSocket a), (Ref String b)] ())
(send ws msg)
queues a text message for sending on the WebSocket connection.
send-binary
(Fn [(Ref WebSocket a), (Ref (Array Byte) b)] ())
(send-binary ws data)
queues a binary message for sending on the WebSocket connection.
send-binary-now
(Fn [(Ref WebSocket a), (Ref (Array Byte) b)] ())
(send-binary-now ws data)
sends a binary message immediately, bypassing the outbox.
Like send-now but for binary data.
send-now
(Fn [(Ref WebSocket a), (Ref String b)] ())
(send-now ws msg)
sends a text message immediately, bypassing the outbox. Writes the WebSocket frame directly to the socket. Use this inside handlers that block for a long time (e.g. LLM streaming) so that each message reaches the client without waiting for the handler to return.
set-outbox
(Fn [WebSocket, (Array (Array Byte))] WebSocket)
sets the outbox property of a WebSocket.
set-outbox!
(Fn [(Ref WebSocket a), (Array (Array Byte))] ())
sets the outbox property of a WebSocket in place.
update-fd
(Fn [WebSocket, (Ref (Fn [Int] Int a) b)] WebSocket)
updates the fd property of a WebSocket using a function f.
update-outbox
(Fn [WebSocket, (Ref (Fn [(Array (Array Byte))] (Array (Array Byte)) a) b)] WebSocket)
updates the outbox property of a WebSocket using a function f.