Struct loole::Receiver

source ·
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§

source§

impl<T> Receiver<T>

source

pub fn try_recv(&self) -> Result<T, TryRecvError>

Attempts to receive a value from the channel associated with this receiver, returning an error if the channel is empty or if all senders have been dropped.

This method will block until a value is available on the channel, or until the channel is empty or all senders have been dropped.

source

pub fn recv_async(&self) -> RecvFuture<T>

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.

This method returns a future that will be resolved with the value received from the channel, or with an error if the channel is closed.

source

pub fn recv(&self) -> Result<T, RecvError>

Wait for an incoming value from the channel associated with this receiver. If all senders have been dropped and there are no more messages in the channel, this method will return an error.

source

pub fn recv_timeout(&self, timeout: Duration) -> Result<T, RecvTimeoutError>

Receives a value from the channel associated with this receiver, blocking the current thread until a value is available or the timeout expires.

source

pub fn recv_deadline(&self, deadline: Instant) -> Result<T, RecvTimeoutError>

Receives a value from the channel associated with this receiver, blocking the current thread until a value is available or the deadline has passed.

source

pub fn drain(&self) -> Drain<'_, 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.

source

pub fn iter(&self) -> Iter<'_, T>

Returns a blocking iterator over the values received on the channel. The iterator will finish iteration when all senders have been dropped.

source

pub fn try_iter(&self) -> TryIter<'_, T>

An iterator over the values received on the channel that finishes iteration when all senders have been dropped or the channel is empty.

This iterator is non-blocking, meaning that it will not wait for the next value to be available if there is not one already. If there is no value available, the iterator will return None.

source

pub fn same_channel(&self, other: &Receiver<T>) -> bool

Returns true if the two receivers belong to the same channel, and false otherwise.

source

pub fn len(&self) -> usize

Returns the number of messages currently in the channel.

This function is useful for determining how many messages are waiting to be processed by consumers, or for implementing backpressure mechanisms.

source

pub fn capacity(&self) -> Option<usize>

Returns the capacity of the channel, if it is bounded. Otherwise, returns None.

source

pub fn is_empty(&self) -> bool

Returns true if the channel is empty.

Note: Zero-capacity channels are always empty.

source

pub fn is_full(&self) -> bool

Returns true if the channel is full.

Note: Zero-capacity channels are always full.

source

pub fn close(&self) -> bool

Closes the channel.

Returns true only if this call actively closed the channel, which was previously open.

The remaining messages can still be received.

source

pub fn is_closed(&self) -> bool

Returns true if the channel is closed.

Trait Implementations§

source§

impl<T> Clone for Receiver<T>

source§

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 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T> Debug for Receiver<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Drop for Receiver<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a, T> IntoIterator for &'a Receiver<T>

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T> IntoIterator for Receiver<T>

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.