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);
});
Trait Implementations
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
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
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