pub struct UpdateStream { /* private fields */ }Expand description
Multiplexed per-market update stream. There is exactly one UpdateStream
per dispatcher; calling OrderBookWebSocket::updates() twice returns
None the second time.
Why take-once semantics: the underlying channel is MPMC, so cloning the receiver and handing one out per call would split messages between receivers in a way callers cannot detect — every test harness or debug sidecar that “just adds a second consumer” would silently lose half the stream. Take-once turns that footgun into a compile-checked None at the call site.
Backed by flume, an MPMC channel with lighter-weight wakers than
async-channel’s; the per-message recv on the consumer side is a
significant fraction of the WS pipeline p99, and flume’s atomic-only
fast path stays out of the parking_lot machinery on uncontended
recv. The channel is bounded; when full the producer raises
SessionEvent::Lagged + SessionEvent::BookInvalidated rather than
dropping deltas silently.
Implementations§
Source§impl UpdateStream
impl UpdateStream
Sourcepub async fn next(&self) -> Option<WsUpdate>
pub async fn next(&self) -> Option<WsUpdate>
Await the next update. None once the producer has been dropped.
Sourcepub fn try_next(&self) -> Result<Option<WsUpdate>, TryRecvError>
pub fn try_next(&self) -> Result<Option<WsUpdate>, TryRecvError>
Non-blocking peek. Returns Ok(Some) if an update is ready,
Ok(None) if the channel is empty, Err if closed.