pub struct Receiver<T> { /* private fields */ }
Expand description
The receiving end of a channel.
Note: Cloning the receiver does not turn this channel into a broadcast channel. Each message will only be received by a single receiver. This is useful for implementing work stealing for concurrent programs.
Implementations
sourceimpl<T> Receiver<T>
impl<T> Receiver<T>
sourcepub fn recv_async(&self) -> RecvFut<'_, T>ⓘNotable traits for RecvFut<'a, T>impl<'a, T> Future for RecvFut<'a, T> type Output = Result<T, RecvError>;
pub fn recv_async(&self) -> RecvFut<'_, T>ⓘNotable traits for RecvFut<'a, T>impl<'a, T> Future for RecvFut<'a, T> type Output = Result<T, RecvError>;
Asynchronously receive a value from the channel, returning an error if all senders have been dropped. If the channel is empty, the returned future will yield to the async runtime.
sourcepub fn into_recv_async(self) -> RecvFut<'static, T>ⓘNotable traits for RecvFut<'a, T>impl<'a, T> Future for RecvFut<'a, T> type Output = Result<T, RecvError>;
pub fn into_recv_async(self) -> RecvFut<'static, T>ⓘNotable traits for RecvFut<'a, T>impl<'a, T> Future for RecvFut<'a, T> type Output = Result<T, RecvError>;
Convert this receiver into a future that asynchronously receives a single message from the channel, returning an error if all senders have been dropped. If the channel is empty, this future will yield to the async runtime.
sourcepub fn stream(&self) -> RecvStream<'_, T>
pub fn stream(&self) -> RecvStream<'_, T>
Create an asynchronous stream that uses this receiver to asynchronously receive messages from the channel. The receiver will continue to be usable after the stream has been dropped.
sourcepub fn into_stream(self) -> RecvStream<'static, T>
pub fn into_stream(self) -> RecvStream<'static, T>
Convert this receiver into a stream that allows asynchronously receiving messages from the channel.
sourceimpl<T> Receiver<T>
impl<T> Receiver<T>
sourcepub fn try_recv(&self) -> Result<T, TryRecvError>
pub fn try_recv(&self) -> Result<T, TryRecvError>
Attempt to fetch an incoming value from the channel associated with this receiver, returning an error if the channel is empty or if all senders have been dropped.
sourcepub fn recv(&self) -> Result<T, RecvError>
pub fn recv(&self) -> Result<T, RecvError>
Wait for an incoming value from the channel associated with this receiver, returning an error if all senders have been dropped.
sourcepub fn recv_deadline(&self, deadline: Instant) -> Result<T, RecvTimeoutError>
pub fn recv_deadline(&self, deadline: Instant) -> Result<T, RecvTimeoutError>
Wait for an incoming value from the channel associated with this receiver, returning an error if all senders have been dropped or the deadline has passed.
sourcepub fn recv_timeout(&self, dur: Duration) -> Result<T, RecvTimeoutError>
pub fn recv_timeout(&self, dur: Duration) -> Result<T, RecvTimeoutError>
Wait for an incoming value from the channel associated with this receiver, returning an error if all senders have been dropped or the timeout has expired.
sourcepub fn iter(&self) -> Iter<'_, T>ⓘNotable traits for Iter<'a, T>impl<'a, T> Iterator for Iter<'a, T> type Item = T;
pub fn iter(&self) -> Iter<'_, T>ⓘNotable traits for Iter<'a, T>impl<'a, T> Iterator for Iter<'a, T> type Item = T;
Create a blocking iterator over the values received on the channel that finishes iteration when all senders have been dropped.
You can also create a self-owned iterator with Receiver::into_iter
.
sourcepub fn try_iter(&self) -> TryIter<'_, T>ⓘNotable traits for TryIter<'a, T>impl<'a, T> Iterator for TryIter<'a, T> type Item = T;
pub fn try_iter(&self) -> TryIter<'_, T>ⓘNotable traits for TryIter<'a, T>impl<'a, T> Iterator for TryIter<'a, T> type Item = T;
A non-blocking iterator over the values received on the channel that finishes iteration when all senders have been dropped or the channel is empty.
sourcepub fn drain(&self) -> Drain<'_, T>ⓘNotable traits for Drain<'a, T>impl<'a, T> Iterator for Drain<'a, T> type Item = T;
pub fn drain(&self) -> Drain<'_, T>ⓘNotable traits for Drain<'a, T>impl<'a, T> Iterator for Drain<'a, T> type Item = T;
Take all msgs currently sitting in the channel and produce an iterator over them. Unlike
try_iter
, the iterator will not attempt to fetch any more values from the channel once
the function has been called.
sourcepub fn is_disconnected(&self) -> bool
pub fn is_disconnected(&self) -> bool
Returns true if all senders for this channel have been dropped.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the channel is empty. Note: Zero-capacity channels are always empty.
Trait Implementations
sourceimpl<T> Clone for Receiver<T>
impl<T> Clone for Receiver<T>
sourcefn clone(&self) -> Self
fn clone(&self) -> Self
Clone this receiver. Receiver
acts as a handle to the ending a channel. Remaining
channel contents will only be cleaned up when all senders and the receiver have been
dropped.
Note: Cloning the receiver does not turn this channel into a broadcast channel. Each message will only be received by a single receiver. This is useful for implementing work stealing for concurrent programs.
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'a, T> IntoIterator for &'a Receiver<T>
impl<'a, T> IntoIterator for &'a Receiver<T>
This exists as a shorthand for Receiver::iter
.
sourceimpl<T> IntoIterator for Receiver<T>
impl<T> IntoIterator for Receiver<T>
Auto Trait Implementations
impl<T> RefUnwindSafe 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> UnwindSafe for Receiver<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more