baml.ws.WebSocket

A WebSocket connection.

Reference version

Signature

class baml.ws.WebSocket

A WebSocket connection.

Source:<builtin>/baml/ns_ws/ws.bamlbytes 89–1819

Fields

_handle

$rust_type

Instance methods

function

close

(self, code: int, reason: string) -> null throws baml.errors.InvalidArgument

Begin the closing handshake, sending code and reason to the peer.

This returns as soon as the close frame is queued. The connection ends when the peer echoes it, which next reports as a CloseEvent.

Throws

  • baml.errors.InvalidArgument if code is not one an endpoint may send (RFC 6455: 1000-1003, 1007-1013, 3000-3999, 4000-4999; not the undefined codes or the inferred-only 1004/1005/1006/1015), or if reason exceeds 123 bytes, the most a close frame can carry.
function

next

(self) -> string | uint8array | baml.ws.CloseEvent throws baml.errors.Io

Block until the next frame arrives.

A text frame is a string and a binary frame a uint8array. Pings are answered here automatically, and neither ping nor pong frames surface. Once the connection ends — closed by either party, or dropped — this returns the same CloseEvent on every call, so a receive loop terminates on the first one rather than blocking forever.

Throws

  • baml.errors.Io if the connection fails while receiving.
function

send

(self, data: string | uint8array) -> null throws baml.errors.Io

Send one frame: a string becomes a text frame, a uint8array a binary one.

Throws

  • baml.errors.Io if the connection is already closed, or the send fails.

Implementations

baml.Concrete for T

Static methods

function

type

() -> reflect.Type throws never

This type's runtime type value: int.type() is the same value as reflect.Type.of<int>().

Spell it on a declared type written as one name, optionally qualified or with generic arguments: Foo.type(), root.models.Base.type(), Box<int[]>.type(). Array, optional, union, map and function types, interfaces, and generic type parameters keep the reflect.Type.of<T>() form. A type that declares its own type member keeps resolving to it.

Source:<builtin>/baml/core.bamlbytes 1360–1392