ps-mpmc 0.1.0-1

multi-producer multi-consumer queue
Documentation
use std::sync::mpsc::RecvError;

use crate::Receiver;

impl<T> Receiver<T> {
    /// 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.
    pub fn recv(&self) -> Result<T, RecvError> {
        self.inner.lock().recv()
    }
}