pub struct Rx<F: Flavor> { /* private fields */ }Expand description
A single consumer (receiver) that works in a blocking context.
Additional methods in ChannelShared can be accessed through Deref.
NOTE: Rx is not Clone or Sync.
If you need concurrent access, use MRx instead.
Rx has a Send marker and can be moved to other threads.
The following code is OK:
use crossfire::*;
let (tx, rx) = mpsc::bounded_blocking::<usize>(100);
std::thread::spawn(move || {
let _ = rx.recv();
});
drop(tx);Because Rx does not have a Sync marker, using Arc<Rx> will lose the Send marker.
For your safety, the following code should not compile:
use crossfire::*;
use std::sync::Arc;
let (tx, rx) = mpsc::bounded_blocking(100);
let rx = Arc::new(rx);
std::thread::spawn(move || {
let _ = rx.recv();
});
drop(tx);Implementations§
Source§impl<F: Flavor> Rx<F>
impl<F: Flavor> Rx<F>
Sourcepub fn recv<'a>(&'a self) -> Result<F::Item, RecvError>
pub fn recv<'a>(&'a self) -> Result<F::Item, RecvError>
Receives a message from the channel. This method will block until a message is received or the channel is closed.
Returns Ok(T) on success.
Returns Err(RecvError) if the sender has been dropped.
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) when 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 recv_timeout(
&self,
timeout: Duration,
) -> Result<F::Item, RecvTimeoutError>
pub fn recv_timeout( &self, timeout: Duration, ) -> Result<F::Item, RecvTimeoutError>
Receives a message from the channel with a timeout. Will block 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 is_disconnected(&self) -> bool
pub fn is_disconnected(&self) -> bool
Return true if the other side has closed
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,
pub fn into_async(self) -> AsyncRx<F>
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> BlockingRxTrait<<F as Queue>::Item> for Rx<F>
impl<F: Flavor> BlockingRxTrait<<F as Queue>::Item> for Rx<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