pub struct Consumer<T> { /* private fields */ }Expand description
The consuming side of a shared state channel.
Consumers have read-only access to the shared value and are notified when
a producer modifies it. Cloning a consumer increments the consumer reference
count. When the last consumer is dropped, all waiters (e.g. Producer::unused)
are notified.
Implementations§
Source§impl<T> Consumer<T>
impl<T> Consumer<T>
Sourcepub fn poll<F, R>(&self, waiter: &Waiter, f: F) -> Poll<Result<R, Ref<'_, T>>>
pub fn poll<F, R>(&self, waiter: &Waiter, f: F) -> Poll<Result<R, Ref<'_, T>>>
Poll the shared state with a closure.
Calls f with a Ref. If f returns Poll::Pending and the
channel is still open, registers the Waiter for notification.
Returns Err(Ref) if the channel has been closed while the
condition returned by f is still pending.
Sourcepub fn poll_closed(&self, waiter: &Waiter) -> Poll<()>
pub fn poll_closed(&self, waiter: &Waiter) -> Poll<()>
Poll for channel closure, registering the waiter if still open.
Sourcepub async fn wait<F, R>(&self, f: F) -> Result<R, Ref<'_, T>>
pub async fn wait<F, R>(&self, f: F) -> Result<R, Ref<'_, T>>
Wait for the closure to return Poll::Ready, re-polling on each state change.
Returns Ok(R) when the closure returns Poll::Ready, or Err(Ref) with
read-only access to the final state if the channel closes first.
Sourcepub fn produce(&self) -> Option<Producer<T>>
pub fn produce(&self) -> Option<Producer<T>>
Upgrade to a Producer, returning None if the state is already closed.
Sourcepub fn same_channel(&self, other: &Self) -> bool
pub fn same_channel(&self, other: &Self) -> bool
Returns true if both consumers share the same underlying state.