pub struct WeakUnboundedSender<T> { /* private fields */ }Expand description
A sender that does not keep the channel open.
When every UnboundedSender is dropped and only WeakUnboundedSenders
remain, the channel is closed for the receiver. upgrade
turns it into an UnboundedSender while one exists.
use nuclei::sync::mpsc;
let (tx, _rx) = mpsc::unbounded_channel::<i32>();
let weak = tx.downgrade();
assert!(weak.upgrade().is_some());
drop(tx);
assert!(weak.clone().upgrade().is_none());§Progress
clone, drop, strong_count and
weak_count are wait-free. upgrade
is lock-free, not wait-free: it is a compare-and-swap on the sender count
that retries when a sender was cloned or dropped meanwhile.
Implementations§
Source§impl<T> WeakUnboundedSender<T>
impl<T> WeakUnboundedSender<T>
Sourcepub fn upgrade(&self) -> Option<UnboundedSender<T>>
pub fn upgrade(&self) -> Option<UnboundedSender<T>>
Tries to turn the weak sender into an UnboundedSender.
Returns Some while at least one UnboundedSender is alive, and
None once the last is gone.
Sourcepub fn strong_count(&self) -> usize
pub fn strong_count(&self) -> usize
How many UnboundedSender handles exist.
Sourcepub fn weak_count(&self) -> usize
pub fn weak_count(&self) -> usize
How many WeakUnboundedSender handles exist.
Trait Implementations§
Source§impl<T> Clone for WeakUnboundedSender<T>
impl<T> Clone for WeakUnboundedSender<T>
Source§impl<T> Debug for WeakUnboundedSender<T>
impl<T> Debug for WeakUnboundedSender<T>
Source§impl<T> Drop for WeakUnboundedSender<T>
impl<T> Drop for WeakUnboundedSender<T>
Auto Trait Implementations§
impl<T> Freeze for WeakUnboundedSender<T>
impl<T> RefUnwindSafe for WeakUnboundedSender<T>
impl<T> Send for WeakUnboundedSender<T>where
T: Send,
impl<T> Sync for WeakUnboundedSender<T>where
T: Send,
impl<T> Unpin for WeakUnboundedSender<T>
impl<T> UnsafeUnpin for WeakUnboundedSender<T>
impl<T> UnwindSafe for WeakUnboundedSender<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more