Struct UnboundedReceiver
struct UnboundedReceiver<T> { ... }
Receive values from the associated UnboundedSender.
Instances are created by the unbounded_channel function.
This receiver can be turned into a Stream using UnboundedReceiverStream.
Implementations
impl<T> UnboundedReceiver<T>
async fn recv(self: &mut Self) -> Option<T>Receives the next value for this receiver.
This method returns
Noneif the channel has been closed and there are no remaining messages in the channel's buffer. This indicates that no further values can ever be received from thisReceiver. The channel is closed when all senders have been dropped, or whencloseis called.If there are no messages in the channel's buffer, but the channel has not yet been closed, this method will sleep until a message is sent or the channel is closed.
Cancel safety
This method is cancel safe. If
recvis used as the event in atokio::select!statement and some other branch completes first, it is guaranteed that no messages were received on this channel.Examples
use mpsc; asyncValues are buffered:
use mpsc; asyncasync fn recv_many(self: &mut Self, buffer: &mut Vec<T>, limit: usize) -> usizeReceives the next values for this receiver and extends
buffer.This method extends
bufferby no more than a fixed number of values as specified bylimit. Iflimitis zero, the function returns immediately with0. The return value is the number of values added tobuffer.For
limit > 0, if there are no messages in the channel's queue, but the channel has not yet been closed, this method will sleep until a message is sent or the channel is closed.For non-zero values of
limit, this method will never return0unless the channel has been closed and there are no remaining messages in the channel's queue. This indicates that no further values can ever be received from thisReceiver. The channel is closed when all senders have been dropped, or whencloseis called.The capacity of
bufferis increased as needed.Cancel safety
This method is cancel safe. If
recv_manyis used as the event in atokio::select!statement and some other branch completes first, it is guaranteed that no messages were received on this channel.Examples
use mpsc; asyncfn try_recv(self: &mut Self) -> Result<T, TryRecvError>Tries to receive the next value for this receiver.
This method returns the
Emptyerror if the channel is currently empty, but there are still outstanding senders or permits.This method returns the
Disconnectederror if the channel is currently empty, and there are no outstanding senders or permits.Unlike the
poll_recvmethod, this method will never return anEmptyerror spuriously.Examples
use mpsc; use TryRecvError; asyncfn blocking_recv(self: &mut Self) -> Option<T>Blocking receive to call outside of asynchronous contexts.
Panics
This function panics if called within an asynchronous execution context.
Examples
use thread; use mpsc; asyncfn blocking_recv_many(self: &mut Self, buffer: &mut Vec<T>, limit: usize) -> usizeVariant of
Self::recv_manyfor blocking contexts.The same conditions as in
Self::blocking_recvapply.fn close(self: &mut 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.
To guarantee that no messages are dropped, after calling
close(),recv()must be called untilNoneis returned.fn is_closed(self: &Self) -> boolChecks if a channel is closed.
This method returns
trueif the channel has been closed. The channel is closed when allUnboundedSenderhave been dropped, or whenUnboundedReceiver::closeis called.Examples
use mpsc; asyncfn is_empty(self: &Self) -> boolChecks if a channel is empty.
This method returns
trueif the channel has no messages.Examples
use mpsc; asyncfn len(self: &Self) -> usizeReturns the number of messages in the channel.
Examples
use mpsc; asyncfn poll_recv(self: &mut Self, cx: &mut Context<'_>) -> Poll<Option<T>>Polls to receive the next message on this channel.
This method returns:
Poll::Pendingif no messages are available but the channel is not closed, or if a spurious failure happens.Poll::Ready(Some(message))if a message is available.Poll::Ready(None)if the channel has been closed and all messages sent before it was closed have been received.
When the method returns
Poll::Pending, theWakerin the providedContextis scheduled to receive a wakeup when a message is sent on any receiver, or when the channel is closed. Note that on multiple calls topoll_recvorpoll_recv_many, only theWakerfrom theContextpassed to the most recent call is scheduled to receive a wakeup.If this method returns
Poll::Pendingdue to a spurious failure, then theWakerwill be notified when the situation causing the spurious failure has been resolved. Note that receiving such a wakeup does not guarantee that the next call will succeed — it could fail with another spurious failure.fn poll_recv_many(self: &mut Self, cx: &mut Context<'_>, buffer: &mut Vec<T>, limit: usize) -> Poll<usize>Polls to receive multiple messages on this channel, extending the provided buffer.
This method returns:
Poll::Pendingif no messages are available but the channel is not closed, or if a spurious failure happens.Poll::Ready(count)wherecountis the number of messages successfully received and stored inbuffer. This can be less than, or equal to,limit.Poll::Ready(0)iflimitis set to zero or when the channel is closed.
When the method returns
Poll::Pending, theWakerin the providedContextis scheduled to receive a wakeup when a message is sent on any receiver, or when the channel is closed. Note that on multiple calls topoll_recvorpoll_recv_many, only theWakerfrom theContextpassed to the most recent call is scheduled to receive a wakeup.Note that this method does not guarantee that exactly
limitmessages are received. Rather, if at least one message is available, it returns as many messages as it can up to the given limit. This method returns zero only if the channel is closed (or iflimitis zero).Examples
use ; use Pin; use mpsc; use Future; asyncfn sender_strong_count(self: &Self) -> usizeReturns the number of
UnboundedSenderhandles.fn sender_weak_count(self: &Self) -> usizeReturns the number of
WeakUnboundedSenderhandles.
impl<T> Any for UnboundedReceiver<T>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for UnboundedReceiver<T>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for UnboundedReceiver<T>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> Debug for UnboundedReceiver<T>
fn fmt(self: &Self, fmt: &mut Formatter<'_>) -> Result
impl<T> Freeze for UnboundedReceiver<T>
impl<T> From for UnboundedReceiver<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> RefUnwindSafe for UnboundedReceiver<T>
impl<T> Send for UnboundedReceiver<T>
impl<T> Sync for UnboundedReceiver<T>
impl<T> Unpin for UnboundedReceiver<T>
impl<T> UnsafeUnpin for UnboundedReceiver<T>
impl<T> UnwindSafe for UnboundedReceiver<T>
impl<T, U> Into for UnboundedReceiver<T>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for UnboundedReceiver<T>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for UnboundedReceiver<T>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>