-
Notifications
You must be signed in to change notification settings - Fork 626
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
New poll_immediate functions to immediately return from a poll #2452
Conversation
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.
Thanks for the PR. Almost all of unsafe code used in this PR is not correct. Please use pin-project-lite as existing code does.
#1) New poll_immediate(_unpin) functions to immediately return from a poll on futures and streams
@taiki-e I think all the checks should pass now, if you can approve the waiting workflow. |
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.
Some futures expect it will be polled until complete, and such usage may cause problems. (see smol-rs/async-io#37 (comment))
Also, creating futures frequently and then dropping them may cause performance problems. (see #2173)
I am not strongly opposed to adding such features, but I think it would be preferable to mention these issues in the documentation.
…re. Removing the poll_immediate_reuse function.
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.
Thanks. LGTM aside from a nit.
Co-authored-by: Taiki Endo <te316e89@gmail.com>
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.
Thanks!
Published in 0.3.17 |
I can open an issue as well if needed, but since I've already done the work I thought it would be just as easy to actually talk about the additions proposed in the pull request.
The reasons for these new functions are because I'm using a tokio::sync::mpsc::Receiver and sometimes I need to just wait until a value is ready and sometimes I need to check if one is ready and if not do some other processing. This can be accomplished by doing
but it seems like it would be nice to have a dedicated Future for this that works better with IDE's.
I could probably use the
now_or_never()
function fromFuturesExt
, but that consumes the future and these new functions and futures allow for polling repeatedly (due to the Stream implementation) to see if they are done without blocking and they can also get the future back if it isUnpin
which is useful if the futures are expensive to construct or if you want to just wait for them to be done at a later time.Closes #2257