pub struct Producer<T> { /* private fields */ }Expand description
The producing side of a shared state channel.
Producers hold mutable access to the shared value. When the state is modified
through Mut, all registered consumers are automatically notified.
Cloning a producer increments the producer reference count. When the last
producer is dropped, the channel is closed.
Implementations§
Source§impl<T> Producer<T>
impl<T> Producer<T>
Sourcepub fn write(&self) -> Result<Mut<'_, T>, Ref<'_, T>>
pub fn write(&self) -> Result<Mut<'_, T>, Ref<'_, T>>
Acquire mutable access to the shared state.
Returns Ok(Mut) if the channel is open, or Err(Ref) with
read-only access if closed. Only locks once.
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-based mutable access with waker registration.
Calls f with a Mut guard. If f returns Poll::Pending,
registers the Waiter for notification when the state next changes.
Returns Poll::Ready(Err(Ref)) if the channel is closed.
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 async fn unused(&self) -> Result<(), Ref<'_, T>>
pub async fn unused(&self) -> Result<(), Ref<'_, T>>
Wait until all consumers have been dropped.
Returns Ok(()) when no consumers remain, or Err(Ref) if the channel closes first.
Sourcepub fn same_channel(&self, other: &Self) -> bool
pub fn same_channel(&self, other: &Self) -> bool
Returns true if both producers share the same underlying state.