Skip to main content

Module stream

Module stream 

Source
Expand description

SSE parser + generic EventStream<T>.

The parser is hand-rolled over a byte stream supplied by reqwest on native targets and the browser’s Fetch/ReadableStream APIs on WebAssembly. It handles data: accumulation, the data: [DONE] terminator, comment lines (: prefix), \r\n and bare \r line endings, and events split across chunk boundaries.

Reconnection: when the underlying body stream errors on a transient failure, the stream re-opens via the caller-supplied closure with exponential backoff capped at MAX_RECONNECT_BACKOFF. Reconnects are counted across the lifetime of the stream, so an intermittent connection cannot exceed the configured request-replay budget. Non-transient errors and exhausted budget surface as Err and terminate the stream.

Cancellation: dropping the EventStream drops the native response stream or aborts the browser Fetch request. No explicit CancellationToken is required — combine with tokio::select! on native targets or an abortable local future in the browser.

Structs§

EventStream
A stream of deserialized SSE events.