Struct discro::Subscriber
source · pub struct Subscriber<T> { /* private fields */ }Expand description
Read a shared value and receive change notifications asynchronously.
Implementations§
source§impl<T> Subscriber<T>
impl<T> Subscriber<T>
sourcepub fn read(&self) -> Ref<T>
pub fn read(&self) -> Ref<T>
Obtain a reference to the most recent value.
Outstanding borrows hold a read lock. Trying to read the value again while already holding a read lock might cause a deadlock!
sourcepub fn read_ack(&mut self) -> Ref<T>
pub fn read_ack(&mut self) -> Ref<T>
Obtain a reference to the most recent value and mark that value as seen by acknowledging it.
Returns a tuple with the borrowed value and a changed flag that indicates if changes have been detected and acknowledged.
Callers must be prepared to handle false positive results, i.e.
if the changed flag returns true even though the shared value
has not been modified. The accuracy of the changed flag depends
on the underlying implementation.
Outstanding borrows hold a read lock. Trying to read the value again while already holding a read lock might cause a deadlock!
sourcepub async fn changed(&mut self) -> Result<(), OrphanedSubscriberError>
pub async fn changed(&mut self) -> Result<(), OrphanedSubscriberError>
Receive change notifications for the shared value.
Waits for a change notification, then marks the newest value as seen.
Errors
Returns Err(OrphanedSubscriberError) if the subscriber is disconnected from the publisher.
sourcepub fn into_stream<U>(
self,
capture_fn: impl FnMut(&T) -> U
) -> impl Stream<Item = U>
pub fn into_stream<U>( self, capture_fn: impl FnMut(&T) -> U ) -> impl Stream<Item = U>
Observe modifications as a stream of captured values.
The capture_fn closure is invoked on a borrowed value while the lock is held.
Returns a stream of captured values, starting with the current value.