pub struct Receiver<T> { /* private fields */ }Implementations§
Source§impl<T> Receiver<T>
impl<T> Receiver<T>
Sourcepub fn recv(&self) -> Result<T, RecvError>
pub fn recv(&self) -> Result<T, RecvError>
Blocks the current thread until a message is received or the channel is disconnected.
§Blocking
- If no message is ready and at least one Sender still
exists, execution is suspended until either
- a message is sent, or
- every Sender is dropped.
§Buffered
- Messages sent before the last Sender is dropped are still delivered.
§Errors
Once all senders are gone, and all buffered messages are consumed,
all subsequent calls return RecvError.
§Safety
Channels are prone to deadlocks. You shall ensure a message will be sent via a corresponding Sender, or that all corresponding Senders will be dropped.
§Examples
use ps_mpmc::channel;
let (tx, rx) = channel::<i32>().into_parts();
std::thread::spawn(move || { tx.send(42).unwrap(); });
assert_eq!(rx.recv(), Ok(42));
assert_eq!(rx.recv(), Err(std::sync::mpsc::RecvError));See also std::sync::mpsc::Receiver::recv for details of the underlying implementation.
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Receiver<T>
impl<T> !UnwindSafe for Receiver<T>
impl<T> Freeze for Receiver<T>
impl<T> Send for Receiver<T>where
T: Send,
impl<T> Sync for Receiver<T>where
T: Send,
impl<T> Unpin for Receiver<T>
impl<T> UnsafeUnpin for Receiver<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more