AsyncRxTrait

Trait AsyncRxTrait 

Source
pub trait AsyncRxTrait<T: Unpin + Send + 'static>:
    Send
    + 'static
    + Debug
    + Display
    + AsRef<ChannelShared<T>>
    + Into<AsyncStream<T>> {
    // Required methods
    fn recv<'a>(&'a self) -> RecvFuture<'a, T> ;
    fn recv_timeout<'a>(
        &'a self,
        timeout: Duration,
    ) -> RecvTimeoutFuture<'a, T, ()> ;
    fn recv_with_timer<'a, F, R>(
        &'a self,
        fut: F,
    ) -> RecvTimeoutFuture<'a, T, R> 
       where F: Future<Output = R> + 'static;
    fn try_recv(&self) -> Result<T, TryRecvError>;
    fn clone_to_vec(self, count: usize) -> Vec<Self>
       where Self: Sized;

    // Provided methods
    fn len(&self) -> usize { ... }
    fn capacity(&self) -> Option<usize> { ... }
    fn is_empty(&self) -> bool { ... }
    fn is_full(&self) -> bool { ... }
    fn is_disconnected(&self) -> bool { ... }
}
Expand description

For writing generic code with MAsyncRx & AsyncRx

Required Methods§

Source

fn recv<'a>(&'a self) -> RecvFuture<'a, T>

Receive message, will await when channel is empty.

Returns Ok(T) when successful.

returns Err(RecvError) when all Tx dropped.

Source

fn recv_timeout<'a>(&'a self, timeout: Duration) -> RecvTimeoutFuture<'a, T, ()>

Available on crate features tokio or async_std only.

Waits for a message to be received from the channel, but only for a limited time. Will await when channel is empty.

The behavior is atomic, either successfully polls a message, or operation cancelled due to timeout.

Returns Ok(T) when successful.

Returns Err(RecvTimeoutError::Timeout) when a message could not be received because the channel is empty and the operation timed out.

returns Err(RecvTimeoutError::Disconnected) when all Tx dropped and channel is empty.

Source

fn recv_with_timer<'a, F, R>(&'a self, fut: F) -> RecvTimeoutFuture<'a, T, R>
where F: Future<Output = R> + 'static,

Receives a message from the channel with a custom timer function (from other async runtime).

The behavior is atomic: the message is either received successfully or the operation is canceled due to a timeout.

Returns Ok(T) when successful.

Returns Err(RecvTimeoutError::Timeout) when a message could not be received because the channel is empty and the operation timed out.

Returns Err(RecvTimeoutError::Disconnected) if the sender has been dropped and the channel is empty.

§Argument:
  • fut: The sleep function. It’s possible to wrap this function with cancelable handle, you can control when to stop polling. the return value of fut is ignore. We add generic R just in order to support smol::Timer.
Source

fn try_recv(&self) -> Result<T, TryRecvError>

Try to receive message, non-blocking.

Returns Ok(T) when successful.

Returns Err(TryRecvError::Empty) when channel is empty.

Returns Err(TryRecvError::Disconnected) when all Tx dropped and channel is empty.

Source

fn clone_to_vec(self, count: usize) -> Vec<Self>
where Self: Sized,

Provided Methods§

Source

fn len(&self) -> usize

The number of messages in the channel at the moment

Source

fn capacity(&self) -> Option<usize>

The capacity of the channel, return None for unbounded channel.

Source

fn is_empty(&self) -> bool

Whether channel is empty at the moment

Source

fn is_full(&self) -> bool

Whether the channel is full at the moment

Source

fn is_disconnected(&self) -> bool

Return true if the other side has closed

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§

Source§

impl<T: Unpin + Send + 'static> AsyncRxTrait<T> for AsyncRx<T>

Source§

impl<T: Unpin + Send + 'static> AsyncRxTrait<T> for MAsyncRx<T>