pub struct UnboundedSender<T> { /* private fields */ }
Expand description

Send values to the associated UnboundedReceiver.

Instances are created by the unbounded_channel function.


Attempts to send a message on this UnboundedSender without blocking.

This method is not marked async because sending a message to an unbounded channel never requires any form of waiting. Because of this, the send method can be used in both synchronous and asynchronous code without problems.

If the receive half of the channel is closed, either due to close being called or the UnboundedReceiver having been dropped, this function returns an error. The error includes the value passed to send.

Completes when the receiver has dropped.

This allows the producers to get notified when interest in the produced values is canceled and immediately stop doing work.

Cancel safety

This method is cancel safe. Once the channel is closed, it stays closed forever and all future calls to closed will return immediately.

use tokio::sync::mpsc;

async fn main() {
    let (tx1, rx) = mpsc::unbounded_channel::<()>();
    let tx2 = tx1.clone();
    let tx3 = tx1.clone();
    let tx4 = tx1.clone();
    let tx5 = tx1.clone();
    tokio::spawn(async move {


Checks if the channel has been closed. This happens when the UnboundedReceiver is dropped, or when the UnboundedReceiver::close method is called.

let (tx, rx) = tokio::sync::mpsc::unbounded_channel::<()>();

let tx2 = tx.clone();


Returns true if senders belong to the same channel.

let (tx, rx) = tokio::sync::mpsc::unbounded_channel::<()>();
let  tx2 = tx.clone();

let (tx3, rx3) = tokio::sync::mpsc::unbounded_channel::<()>();

Converts the UnboundedSender to a WeakUnboundedSender that does not count towards RAII semantics, i.e. if all UnboundedSender instances of the channel were dropped and only WeakUnboundedSender instances remain, the channel is closed.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.