Struct glommio::channels::local_channel::LocalSender [−][src]
pub struct LocalSender<T> { /* fields omitted */ }
Expand description
Send endpoint to the local_channel
Implementations
Sends data into this channel.
It returns a GlommioError::Closed
encapsulating a BrokenPipe
if
the receiver is destroyed. It returns a GlommioError::WouldBlock
encapsulating a WouldBlock
if this is a bounded channel that has no
more capacity
Examples
use futures_lite::StreamExt;
use glommio::{channels::local_channel, Local, LocalExecutor};
let ex = LocalExecutor::default();
ex.run(async move {
let (sender, receiver) = local_channel::new_bounded(1);
sender.try_send(0);
sender.try_send(0).unwrap_err(); // no more capacity
receiver.stream().next().await.unwrap(); // now we have capacity again
drop(receiver); // but because the receiver is destroyed send will err
sender.try_send(0).unwrap_err();
});
Sends data into this channel when it is ready to receive it
For an unbounded channel this is just a more expensive version of
try_send
. Prefer to use try_send
instead.
For a bounded channel this will push to the channel when the channel is ready to receive data.
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();
drop(receiver);
});
Checks if there is room to send data in this channel
Examples
use glommio::{channels::local_channel, Local, LocalExecutor};
let ex = LocalExecutor::default();
ex.run(async move {
let (sender, receiver) = local_channel::new_bounded(1);
assert_eq!(sender.is_full(), false);
sender.try_send(0);
assert_eq!(sender.is_full(), true);
drop(receiver);
});
Returns the number of items still queued in this channel
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();
sender.try_send(0);
sender.try_send(0);
assert_eq!(sender.len(), 2);
receiver.stream().next().await.unwrap();
assert_eq!(sender.len(), 1);
drop(receiver);
});
Trait Implementations
Auto Trait Implementations
impl<T> !RefUnwindSafe for LocalSender<T>
impl<T> !Send for LocalSender<T>
impl<T> !Sync for LocalSender<T>
impl<T> Unpin for LocalSender<T>
impl<T> !UnwindSafe for LocalSender<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