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

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

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 futures_lite::StreamExt;
use glommio::{channels::local_channel, Local, LocalExecutor};

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

    let h = Local::local(async move {
        let sum = receiver.stream().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

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::{channels::local_channel, Local, LocalExecutor};

let ex = LocalExecutor::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);
});

Converts receiver into the [‘Stream’] instance. Each [‘Stream’] instance may handle only single receiver and can not be shared between [‘Tasks’].

Trait Implementations

Formats the value using the given formatter. Read more

Executes the destructor for this type. 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

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. 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.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more