pub struct SignalStream<T>where
T: Clone,{ /* private fields */ }Expand description
A stream of signal value changes.
SignalStream wraps a broadcast receiver and provides filtering capabilities. It implements async iteration for use in event loops.
Implementations§
Source§impl<T> SignalStream<T>where
T: Clone,
impl<T> SignalStream<T>where
T: Clone,
Sourcepub fn new(receiver: Receiver<T>, signal_id: SignalId) -> SignalStream<T>
pub fn new(receiver: Receiver<T>, signal_id: SignalId) -> SignalStream<T>
Create a new signal stream.
Sourcepub fn filter<F>(self, predicate: F) -> SignalStream<T>
pub fn filter<F>(self, predicate: F) -> SignalStream<T>
Add a filter to this stream.
Only values matching the predicate will be yielded.
Sourcepub fn try_recv(&mut self) -> Option<T>
pub fn try_recv(&mut self) -> Option<T>
Try to receive the next value without blocking.
Returns None if no value is available or the channel is closed.
Sourcepub async fn recv(&mut self) -> Result<T, ReactiveError>
pub async fn recv(&mut self) -> Result<T, ReactiveError>
Receive the next value, waiting if necessary.
Returns an error if the channel is closed.
Signal subscriptions are eventually consistent rather than lossless: if a subscriber lags behind the broadcast buffer under sustained load, intermediate values may be dropped and the next received value will be a newer snapshot. Handlers are expected to log lag events so the loss is diagnosable.