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

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

Send endpoint to the local_channel

Implementations

impl<T> LocalSender<T>[src]

pub fn try_send(&self, item: T) -> Result<(), ChannelError<T>>[src]

Sends data into this channel.

It returns a ChannelError encapsulating a BrokenPipe if the receiver is destroyed. It returns a ChannelError encapsulating a WouldBlock if this is a bounded channel that has no more capacity

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_bounded(1);
    sender.try_send(0);
    sender.try_send(0).unwrap_err(); // no more capacity
    receiver.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();
});

pub async fn send<'_>(&'_ self, item: T) -> Result<(), ChannelError<T>>[src]

Sends data into this channel when it is ready to receive it

For an unbounded channel this is just a more expensive version of send. Prefer to use send instead.

For a bounded channel this will push to the channel when the channel is ready to receive data.

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();
    drop(receiver);
});

pub fn is_full(&self) -> bool[src]

Checks if there is room to send data in this channel

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);
    assert_eq!(sender.is_full(), false);
    sender.try_send(0);
    assert_eq!(sender.is_full(), true);
    drop(receiver);
});

pub fn len(&self) -> usize[src]

Returns the number of items still queued in this channel

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();
    sender.try_send(0);
    sender.try_send(0);
    assert_eq!(sender.len(), 2);
    receiver.next().await.unwrap();
    assert_eq!(sender.len(), 1);
    drop(receiver);
});

Trait Implementations

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

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

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

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<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.