pub struct UnboundedSender<T> { /* private fields */ }Expand description
Sends values to the associated UnboundedReceiver.
Created by unbounded_channel. Cloning it is a reference-count
increment.
§Progress
Wait-free (a bounded number of the caller’s own atomic steps):
is_closed, same_channel,
strong_count, weak_count,
downgrade, clone and drop. The drop of the last
sender ends with a wake of the receiver’s waker cell, which is two atomic
steps; what the waker then does belongs to the executor.
Lock-free, not wait-free: send. It admits the value with a
compare-and-swap that retries when another sender or the receiver changed
the count first, and then pushes onto the message queue, which retries when
it loses a slot to another sender and allocates a segment when the last one
is full. Some thread’s call completes whenever any retries.
closed is lock-free: a poll may queue a waiter.
Implementations§
Source§impl<T> UnboundedSender<T>
impl<T> UnboundedSender<T>
Sourcepub fn send(&self, message: T) -> Result<(), SendError<T>>
pub fn send(&self, message: T) -> Result<(), SendError<T>>
Sends a value, without waiting.
A successful send means the other end had not hung up when the value
was published. Ok does not mean the value will be received: the
receiver can hang up right after.
§Errors
If the receiving half is closed, by UnboundedReceiver::close or by
being dropped, the function returns an error that holds the value.
use nuclei::sync::mpsc;
let (tx, mut rx) = mpsc::unbounded_channel();
tx.send("first").unwrap();
assert_eq!(rx.try_recv(), Ok("first"));
drop(rx);
assert_eq!(tx.send("second").unwrap_err().0, "second");Sourcepub async fn closed(&self)
pub async fn closed(&self)
Completes when the receiver has been closed or dropped.
This lets a producer learn that nobody wants its values any more and stop work early.
§Cancel safety
Cancel safe. Once the channel is closed it stays closed, and every later call completes at once.
use nuclei::sync::mpsc;
let (tx, rx) = mpsc::unbounded_channel::<()>();
let mut cx = Context::from_waker(Waker::noop());
let mut closed = pin!(tx.closed());
assert_eq!(closed.as_mut().poll(&mut cx), Poll::Pending);
drop(rx);
assert_eq!(closed.as_mut().poll(&mut cx), Poll::Ready(()));Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Whether the channel is closed: the receiver was closed or dropped.
use nuclei::sync::mpsc;
let (tx, rx) = mpsc::unbounded_channel::<()>();
assert!(!tx.is_closed());
drop(rx);
assert!(tx.is_closed());Sourcepub fn same_channel(&self, other: &Self) -> bool
pub fn same_channel(&self, other: &Self) -> bool
Whether two senders belong to the same channel.
use nuclei::sync::mpsc;
let (tx, _rx) = mpsc::unbounded_channel::<()>();
let tx2 = tx.clone();
assert!(tx.same_channel(&tx2));
let (tx3, _rx3) = mpsc::unbounded_channel::<()>();
assert!(!tx3.same_channel(&tx2));Sourcepub fn downgrade(&self) -> WeakUnboundedSender<T>
pub fn downgrade(&self) -> WeakUnboundedSender<T>
Converts the sender into a WeakUnboundedSender, which does not keep
the channel open. The sender itself stays.
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.