pub struct Receiver<T> { /* private fields */ }Expand description
The receiving end of a channel which implements the Stream trait.
This is created by the channel function.
§Single waiter
The receiver stores one waker. recv,
poll_recv and Stream::poll_next take &self, but
only the task that polled most recently is woken. Wait for messages from
one task at a time; an earlier concurrent waiter may stay pending even
while messages are buffered.
Implementations§
Source§impl<T> Receiver<T>
impl<T> Receiver<T>
Sourcepub fn sender(&self) -> Sender<T>
pub fn sender(&self) -> Sender<T>
Creates an additional sender for this channel.
Closing is permanent: once the channel is closed, or every sender has
been dropped, the returned sender is closed too and its send() fails.
Sourcepub fn close(&self)
pub fn close(&self)
Closes the receiving half of a channel, without dropping it.
This prevents any further messages from being sent on the channel while still enabling the receiver to drain messages that are buffered.
Sourcepub async fn recv(&self) -> Option<T>
pub async fn recv(&self) -> Option<T>
Waits for the next message.
Returns None once the channel is closed or every sender has been
dropped, and every buffered message has been received.
Only one task may wait at a time; see single waiter.
Sourcepub fn poll_recv(&self, cx: &mut Context<'_>) -> Poll<Option<T>>
pub fn poll_recv(&self, cx: &mut Context<'_>) -> Poll<Option<T>>
Polls for the next message.
Returns Ready(None) once the channel is closed or every sender has
been dropped, and every buffered message has been received.
A pending poll replaces the previously registered waker; see single waiter.
Trait Implementations§
Source§impl<T> FusedStream for Receiver<T>
impl<T> FusedStream for Receiver<T>
Source§fn is_terminated(&self) -> bool
fn is_terminated(&self) -> bool
Returns true once the channel is closed and every buffered message
has been received.
Source§impl<T> Stream for Receiver<T>
impl<T> Stream for Receiver<T>
Source§fn poll_next(
self: Pin<&mut Receiver<T>>,
cx: &mut Context<'_>,
) -> Poll<Option<<Receiver<T> as Stream>::Item>>
fn poll_next( self: Pin<&mut Receiver<T>>, cx: &mut Context<'_>, ) -> Poll<Option<<Receiver<T> as Stream>::Item>>
None if the stream is exhausted. Read more