pub struct Receiver<T> { /* private fields */ }Expand description
The receiving side of a channel.
The receiver can only be called from a single thread.
Implementations§
Source§impl<T> Receiver<T>
impl<T> Receiver<T>
Sourcepub fn try_recv(&mut self) -> Result<T, TryRecvError>
pub fn try_recv(&mut self) -> Result<T, TryRecvError>
Attempts to receive a message immediately.
Sourcepub async fn recv(&mut self) -> Result<T, RecvError>
pub async fn recv(&mut self) -> Result<T, RecvError>
Receives a message asynchronously, if necessary waiting until one becomes available.
Sourcepub async fn recv_timeout<D>(
&mut self,
deadline: D,
) -> Result<T, RecvTimeoutError>
pub async fn recv_timeout<D>( &mut self, deadline: D, ) -> Result<T, RecvTimeoutError>
Receives a message asynchronously, if necessary waiting until one becomes available or until the deadline elapses.
The deadline is specified as a Future that is expected to resolves to
() after some duration, such as a tokio::time::Sleep future.
Sourcepub fn close(&self)
pub fn close(&self)
Closes the queue.
This prevents any further messages from being sent on the channel. Messages that were already sent can still be received, however, which is why a call to this method should typically be followed by a loop receiving all remaining messages.
For this reason, no counterpart to Sender::is_closed is exposed by
the receiver as such method could easily be misused and lead to lost
messages. Instead, messages should be received until a RecvError,
RecvTimeoutError::Closed or TryRecvError::Closed error is
returned.