[][src]Struct tokio::sync::mpsc::Receiver

pub struct Receiver<T> { /* fields omitted */ }

Receive values from the associated Sender.

Instances are created by the channel function.

Methods

impl<T> Receiver<T>[src]

pub fn recv(&'_ mut self) -> impl Future<Output = Option<T>>[src]

Receive the next value for this receiver.

None is returned when all Sender halves have dropped, indicating that no further values can be sent on the channel.

Examples

use tokio::sync::mpsc;

#[tokio::main]
async fn main() {
    let (mut tx, mut rx) = mpsc::channel(100);

    tokio::spawn(async move {
        tx.send("hello").await.unwrap();
    });

    assert_eq!(Some("hello"), rx.recv().await);
    assert_eq!(None, rx.recv().await);
}

Values are buffered:

use tokio::sync::mpsc;

#[tokio::main]
async fn main() {
    let (mut tx, mut rx) = mpsc::channel(100);

    tx.send("hello").await.unwrap();
    tx.send("world").await.unwrap();

    assert_eq!(Some("hello"), rx.recv().await);
    assert_eq!(Some("world"), rx.recv().await);
}

pub fn close(&mut self)[src]

Closes the receiving half of a channel, without dropping it.

This prevents any further messages from being sent on the channel while still enabling the receiver to drain messages that are buffered.

Trait Implementations

impl<T> Debug for Receiver<T>[src]

impl<T> Stream for Receiver<T>[src]

type Item = T

Values yielded by the stream.

Auto Trait Implementations

impl<T> Send for Receiver<T> where
    T: Send

impl<T> Unpin for Receiver<T>

impl<T> Sync for Receiver<T> where
    T: Send

impl<T> !UnwindSafe for Receiver<T>

impl<T> !RefUnwindSafe for Receiver<T>

Blanket Implementations

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<S, T, E> TryStream for S where
    S: Stream<Item = Result<T, E>> + ?Sized
[src]

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

impl<S> TryStreamExt for S where
    S: TryStream + ?Sized
[src]