Sse

Sse :: # (opaque)

Typed server-sent event sources.

Applications describe one finite transition at a time. The platform host owns scheduling, backpressure, framing buffers, compression, cancellation, and the lifetime of the retained source between transitions.

event_id : Str -> Try(EventId, [InvalidEventId])

Validate an SSE event ID. IDs become Last-Event-ID request header values on reconnect, so NUL and line endings are rejected rather than normalized.

clear_event_id : EventId

Emit an empty id: field, clearing the client's retained reconnect ID.

retry_after : U64 -> Retry

Ask the client to use a new reconnect delay, in milliseconds.

unfold! : state, (state => Try(Step(state), err)) => Source

Retain typed application state behind a private affine source. Every invocation returns the next source owner; the host never copies or reconstructs application state.

drop_source_for_host! : Source => {  }

Platform ABI operation; consuming the value lets ARC release the complete retained application state graph.

drop_step_for_host! : StepToHost => {  }

Platform ABI operation used when a returned step cannot be installed.

EventId

:= [AbsentEventId, ClearEventId, SetEventId(Str)]

Event

:= [Event(List(U8))]
to_bytes : Event -> List(U8)

Return the canonical framed bytes for a finite response. Applications normally pass events to an SSE response helper instead of inspecting this representation directly.

keyed : Str, Str, Str -> Event

Construct a named SSE event containing one keyed data value. The common single-line path creates the complete frame once; multiline values fall back to canonical repeated keyed fields.

named : Str, List(Str) -> Event

Construct one named SSE event from already-keyed data fields. Event names have line endings removed so they cannot create a second SSE field. Every logical line in a data field is emitted as its own data: line.

named_with : Str, List(Str), EventOptions -> Event

Construct a named event with optional reconnect ID and retry metadata. The ID is already validated by event_id; all data values remain canonical data: fields.

data : Str -> Event

Construct one SSE data event. Embedded CR, LF, and CRLF line endings are normalized and emitted as one data: field per logical line.

Step

:= [
    Emit({ event : Event, state : state, wake : Wake }),
    Wait({ state : state, wake : Wake }),
    End,
]

StepToHost

:= [
    EmitToHost({ item : List(U8), source : Source, wait_millis : U64 }),
    WaitToHost({ source : Source, wait_millis : U64 }),
    EndToHost,
    ErrorToHost(Str),
]