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

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