-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Future::poll_once
#92116
Add Future::poll_once
#92116
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,32 @@ | ||||||||||||||||||||||||||||||||
use crate::fmt; | ||||||||||||||||||||||||||||||||
use crate::future::Future; | ||||||||||||||||||||||||||||||||
use crate::pin::Pin; | ||||||||||||||||||||||||||||||||
use crate::task::{Context, Poll}; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
/// Resolves to the output of polling a future once. | ||||||||||||||||||||||||||||||||
/// | ||||||||||||||||||||||||||||||||
/// This `struct` is created by [`poll_once()`]. See its | ||||||||||||||||||||||||||||||||
/// documentation for more. | ||||||||||||||||||||||||||||||||
#[unstable(feature = "future_poll_once", issue = "92115")] | ||||||||||||||||||||||||||||||||
pub struct PollOnce<F> { | ||||||||||||||||||||||||||||||||
pub(crate) future: F, | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idea to support
Suggested change
(and a |
||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
#[unstable(feature = "future_poll_once", issue = "92115")] | ||||||||||||||||||||||||||||||||
impl<F> fmt::Debug for PollOnce<F> { | ||||||||||||||||||||||||||||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||||||||||||||||||||||||||||||
f.debug_tuple("PollOnce").finish() | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
#[unstable(feature = "future_poll_once", issue = "92115")] | ||||||||||||||||||||||||||||||||
impl<F> Future for PollOnce<F> | ||||||||||||||||||||||||||||||||
where | ||||||||||||||||||||||||||||||||
F: Future + Unpin, | ||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||
type Output = Poll<F::Output>; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||||||||||||||||||||||||||||||||
Poll::Ready(Pin::new(&mut self.future).poll(cx)) | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
Comment on lines
+25
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
If the dependency on a macro is deemed unsatisfactory to begin with, we could always hand-roll a self.future
.take()
.expect("Polled after completion")
.pinned(|future| Poll::Ready(future.poll(cx))) |
||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Future::poll_once
#92116 (comment))