[][src]Struct glommio::channels::local_channel::LocalReceiver

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

Receive endpoint to the local_channel

The LocalReceiver provides an interface compatible with StreamExt and will keep yielding elements until the sender is destroyed.

Examples

use glommio::{LocalExecutor, Local};
use glommio::channels::local_channel;
use futures_lite::StreamExt;

let ex = LocalExecutor::make_default();
ex.run(async move {
    let (sender, mut receiver) = local_channel::new_unbounded();

    let h = Local::local(async move {
        let sum = receiver.fold(0, |acc, x| acc + x).await;
        assert_eq!(sum, 45);
    }).detach();

    for i in 0..10 {
        sender.try_send(i);
    }
    drop(sender);
    h.await;
});

Implementations

impl<T> LocalReceiver<T>[src]

pub async fn recv<'_>(&'_ self) -> Option<T>[src]

Receives data from this channel

If the sender is no longer available it returns None. Otherwise block until an item is available and returns it wrapped in Some

Notice that this is also available as a Stream. Whether to consume from a stream or recv is up to the application. The biggest difference is that StreamExt's [next] method takes a mutable reference to self. If the LocalReceiver is, say, behind an Rc it may be more ergonomic to recv.

Examples

use glommio::{LocalExecutor, Local};
use glommio::channels::local_channel;

let ex = LocalExecutor::make_default();
ex.run(async move {
    let (sender, receiver) = local_channel::new_bounded(1);
    sender.send(0).await.unwrap();
    let x = receiver.recv().await.unwrap();
    assert_eq!(x, 0);
});

Trait Implementations

impl<T: Debug> Debug for LocalReceiver<T>[src]

impl<T> Drop for LocalReceiver<T>[src]

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

type Item = T

Values yielded by the stream.

Auto Trait Implementations

impl<T> !RefUnwindSafe for LocalReceiver<T>

impl<T> !Send for LocalReceiver<T>

impl<T> !Sync for LocalReceiver<T>

impl<T> Unpin for LocalReceiver<T>

impl<T> !UnwindSafe for LocalReceiver<T>

Blanket Implementations

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

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

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

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

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

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

type Output = T

Should always be Self

impl<S> StreamExt for S where
    S: Stream + ?Sized
[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<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