sync: add Receiver::poll_recv(..)
method
#7059
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
this commit adds a
rx.poll_recv(cx)
method to the public interface oftokio::sync::oneshot::Receiver<T>
.this method has the following signature:
this is similar to the
tokio::sync::mpsc::Receiver::poll_recv
andtokio::sync::mpsc::UnboundedReceiver::poll_recv
methods, which have the following signature:see:
in particular, note the
&mut self
receiver of these methods, as opposed to thePin<&mut Self>
receiver inFuture::poll(..)
. today, a oneshot receiver must be pinned in order to be polled viaFuture::poll(..)
.tokio::sync::oneshot::Receiver::try_recv(..)
has an important but subtle difference frompoll_recv(..)
, alluded to in its documentation:see hyperium/http-body#100 for an example use-case for this.
if we are in the context of an asynchronous task, we may wish to poll on the receiver-end of the channel and register for future notification, indicating that we should be awoken later when a value is ready or when conditions yielding a spurious failure have passed.
providing a means to poll a
&mut Receiver<T>
avoids the performance impact of boxing the receiver as an eraseddyn Future
trait object, or of using antokio::sync::mpsc::Receiver<T>
, or the ergonomic wrinkles of needing to rely on pin projection in asynchronous types that compose on top of oneshot channels.Motivation
Solution