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§
Sourcefn recv<'a>(&'a self) -> RecvFuture<'a, T> ⓘ
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.
Sourcefn recv_timeout<'a>(&'a self, timeout: Duration) -> RecvTimeoutFuture<'a, T, ()> ⓘ
Available on crate features tokio or async_std only.
fn recv_timeout<'a>(&'a self, timeout: Duration) -> RecvTimeoutFuture<'a, T, ()> ⓘ
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.
Sourcefn recv_with_timer<'a, F, R>(&'a self, fut: F) -> RecvTimeoutFuture<'a, T, R> ⓘwhere
F: Future<Output = R> + 'static,
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 offutis ignore. We add genericRjust in order to support smol::Timer.
Sourcefn try_recv(&self) -> Result<T, TryRecvError>
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.
fn clone_to_vec(self, count: usize) -> Vec<Self>where
Self: Sized,
Provided Methods§
Sourcefn capacity(&self) -> Option<usize>
fn capacity(&self) -> Option<usize>
The capacity of the channel, return None for unbounded channel.
Sourcefn is_disconnected(&self) -> bool
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.