pub struct Subscription { /* private fields */ }Expand description
A lag-tolerant subscription to a stream’s frame bus.
Returned by StreamHandle::subscribe_resilient. Unlike a raw
broadcast::Receiver, recv does not terminate when the
consumer falls behind: the dropped span is reported to the Observer as
on_subscriber_lagged and reception
continues from the oldest still-buffered frame. This is the recommended
consumer loop for packagers, recorders, and SFUs.
An optional max_lag bound turns chronic lag into
eviction: once cumulative dropped frames exceed the bound, recv returns
None (after an on_subscriber_evicted
notification) so a hopelessly slow consumer is shed rather than wasting
buffer churn forever.
Implementations§
Source§impl Subscription
impl Subscription
Sourcepub fn max_lag(self, max: u64) -> Self
pub fn max_lag(self, max: u64) -> Self
Evict this subscriber once cumulative dropped frames exceed max.
let sub = handle.subscribe_resilient().max_lag(10_000);Sourcepub async fn recv(&mut self) -> Option<Arc<MediaFrame>>
pub async fn recv(&mut self) -> Option<Arc<MediaFrame>>
Receive the next frame, resynchronizing past any lag.
Returns None when the stream’s sender is dropped (the publisher ended)
or when the max_lag eviction threshold is crossed:
while let Some(frame) = sub.recv().await {
// packetize `frame` …
}Sourcepub fn raw(&mut self) -> &mut Receiver<Arc<MediaFrame>>
pub fn raw(&mut self) -> &mut Receiver<Arc<MediaFrame>>
Borrow the underlying raw receiver, for callers that need
broadcast::Receiver APIs directly.