pub struct MAsyncRx<F: Flavor>(/* private fields */);Expand description
A multi-consumer (receiver) that works in an async context.
Inherits from AsyncRx<F> and implements Clone.
Additional methods in ChannelShared can be accessed through Deref.
You can use into() to convert it to AsyncRx<F>.
MAsyncRx can be converted into MRx via the From trait,
which means you can have two types of receivers, both within async and
blocking contexts, for the same channel.
Implementations§
Source§impl<F: Flavor> MAsyncRx<F>
impl<F: Flavor> MAsyncRx<F>
pub fn into_stream(self) -> AsyncStream<F>
pub fn into_blocking(self) -> MRx<F>
Methods from Deref<Target = AsyncRx<F>>§
Sourcepub fn recv<'a>(&'a self) -> RecvFuture<'a, F> ⓘ
pub fn recv<'a>(&'a self) -> RecvFuture<'a, F> ⓘ
Receives a message from the channel. This method will await until a message is received or the channel is closed.
This function is cancellation-safe, so it’s safe to use with timeout() and the select! macro.
When a RecvFuture is dropped, no message will be received from the channel.
For timeout scenarios, there’s an alternative: AsyncRx::recv_timeout().
Returns Ok(T) on success.
Returns Err(RecvError) if the sender has been dropped.
Sourcepub fn recv_timeout<'a>(
&'a self,
duration: Duration,
) -> RecvTimeoutFuture<'a, F, ()> ⓘ
Available on crate features tokio or async_std only.
pub fn recv_timeout<'a>( &'a self, duration: Duration, ) -> RecvTimeoutFuture<'a, F, ()> ⓘ
tokio or async_std only.Receives a message from the channel with a timeout. Will await when channel is empty.
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.
Sourcepub fn recv_with_timer<'a, FR, R>(
&'a self,
fut: FR,
) -> RecvTimeoutFuture<'a, F, R> ⓘwhere
FR: Future<Output = R> + 'static,
pub fn recv_with_timer<'a, FR, R>(
&'a self,
fut: FR,
) -> RecvTimeoutFuture<'a, F, R> ⓘwhere
FR: 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
§Example:
extern crate smol;
use std::time::Duration;
use crossfire::*;
async fn foo() {
let (tx, rx) = mpmc::bounded_async::<usize>(10);
match rx.recv_with_timer(smol::Timer::after(Duration::from_secs(1))).await {
Ok(_item)=>{
println!("message recv");
}
Err(RecvTimeoutError::Timeout)=>{
println!("timeout");
}
Err(RecvTimeoutError::Disconnected)=>{
println!("sender-side closed");
}
}
}Sourcepub fn try_recv(&self) -> Result<F::Item, TryRecvError>
pub fn try_recv(&self) -> Result<F::Item, TryRecvError>
Attempts to receive a message from the channel without blocking.
Returns Ok(T) on successful.
Returns Err(TryRecvError::Empty) if the channel is empty.
Returns Err(TryRecvError::Disconnected) if the sender has been dropped and the channel is empty.
Sourcepub fn read_select(&self, result: SelectResult) -> Result<F::Item, RecvError>where
F: FlavorSelect,
pub fn read_select(&self, result: SelectResult) -> Result<F::Item, RecvError>where
F: FlavorSelect,
Sourcepub fn is_disconnected(&self) -> bool
pub fn is_disconnected(&self) -> bool
Return true if the other side has closed
Methods from Deref<Target = ChannelShared<F>>§
Trait Implementations§
Source§fn as_ref(&self) -> &ChannelShared<F>
fn as_ref(&self) -> &ChannelShared<F>
Source§impl<F: Flavor + FlavorMC> AsyncRxTrait<<F as Queue>::Item> for MAsyncRx<F>
impl<F: Flavor + FlavorMC> AsyncRxTrait<<F as Queue>::Item> for MAsyncRx<F>
Source§fn capacity(&self) -> Option<usize>
fn capacity(&self) -> Option<usize>
The capacity of the channel, return None for unbounded channel.
Source§fn is_disconnected(&self) -> bool
fn is_disconnected(&self) -> bool
Return true if the other side has closed
fn clone_to_vec(self, count: usize) -> Vec<Self>
Source§fn try_recv(&self) -> Result<F::Item, TryRecvError>
fn try_recv(&self) -> Result<F::Item, TryRecvError>
Source§fn recv<'a>(&'a self) -> impl Future<Output = Result<F::Item, RecvError>> + Send
fn recv<'a>(&'a self) -> impl Future<Output = Result<F::Item, RecvError>> + Send
Source§fn recv_timeout<'a>(
&'a self,
duration: Duration,
) -> impl Future<Output = Result<F::Item, RecvTimeoutError>> + Send
fn recv_timeout<'a>( &'a self, duration: Duration, ) -> impl Future<Output = Result<F::Item, RecvTimeoutError>> + Send
tokio or async_std only.