Skip to main content

UnboundedSender

Struct UnboundedSender 

Source
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>

Source

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");
Source

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(()));
Source

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());
Source

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));
Source

pub fn downgrade(&self) -> WeakUnboundedSender<T>

Converts the sender into a WeakUnboundedSender, which does not keep the channel open. The sender itself stays.

Source

pub fn strong_count(&self) -> usize

How many UnboundedSender handles exist.

Source

pub fn weak_count(&self) -> usize

How many WeakUnboundedSender handles exist.

Trait Implementations§

Source§

impl<T> Clone for UnboundedSender<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for UnboundedSender<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for UnboundedSender<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T> Freeze for UnboundedSender<T>

§

impl<T> RefUnwindSafe for UnboundedSender<T>

§

impl<T> Send for UnboundedSender<T>
where T: Send,

§

impl<T> Sync for UnboundedSender<T>
where T: Send,

§

impl<T> Unpin for UnboundedSender<T>

§

impl<T> UnsafeUnpin for UnboundedSender<T>

§

impl<T> UnwindSafe for UnboundedSender<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.