pub struct StreamOptions {
pub reconnect: bool,
pub max_reconnects: u32,
pub terminal_events: Vec<String>,
pub inactivity_timeout: Option<Duration>,
pub base_retry: Duration,
pub max_backoff: Duration,
pub stability_reset: Duration,
pub on_state: Option<Arc<dyn Fn(StreamState) + Send + Sync>>,
}Expand description
Reconnection and lifecycle behaviour for EventStream. Every field
defaults to a generic, spec-compliant SSE stream; the platform-specific
knobs (terminal events, an inactivity watchdog, retry: pacing) are opt-in
so a caller that passes Default::default gets standard SSE.
Fields§
§reconnect: boolReconnect (replaying Last-Event-ID) when the stream ends. Default true.
max_reconnects: u32Reconnect attempts without progress before giving up. Default 5.
terminal_events: Vec<String>Event names that complete the stream WITHOUT reconnecting. Empty by default: a generic stream reconnects on end and lets the caller stop it.
inactivity_timeout: Option<Duration>Max silence between reads before the socket is presumed dead and a
reconnect is attempted. None disables the watchdog (EOF owns
liveness). Mirrors the platform’s 300 s inactivity timeout: collapsing
it with EOF made a silently-dead socket look like a finished stream.
base_retry: DurationBase reconnect interval; a retry: field overrides it per stream.
max_backoff: DurationCap on the reconnect backoff.
stability_reset: DurationReconnect budget resets after this long connected without a disconnect, so a long healthy stream doesn’t carry “this is the Nth retry” baggage.
on_state: Option<Arc<dyn Fn(StreamState) + Send + Sync>>Optional connection-lifecycle observer. Disconnected is NOT fired when
the caller drops the stream — only on a natural end. Held in an Arc so
StreamOptions stays Clone (it lives inside the cloneable
crate::RequestOptions); share state through the closure’s captures.