Trait AsyncReceiver

Source
pub trait AsyncReceiver<T: Sized + Send + Sync>:
    Sized
    + Send
    + Sync {
    // Required methods
    fn callback(&self, cb: impl Into<ControllerCallback<Self>>);
    fn clear_callback(&self);
    async fn poll(&self) -> ControllerResult<()>;
    async fn try_recv(&self) -> ControllerResult<Option<T>>;

    // Provided method
    async fn recv(&self) -> ControllerResult<T> { ... }
}
Expand description

Asynchronous and thread-safe handle to receive data from a stream. See Controller’s documentation for details.

Details about the sender are left to the implementor.

Required Methods§

Source

fn callback(&self, cb: impl Into<ControllerCallback<Self>>)

Register a callback to be called on receive.

There can only be one callback registered at any given time.

Source

fn clear_callback(&self)

Clear the currently registered callback.

Source

async fn poll(&self) -> ControllerResult<()>

Block until a value is available, without consuming it.

Source

async fn try_recv(&self) -> ControllerResult<Option<T>>

Attempt to receive a value, return None if nothing is currently available.

Provided Methods§

Source

async fn recv(&self) -> ControllerResult<T>

Block until a value is available and returns it.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§