New poll_immediate functions to immediately return from a poll#2452
Merged
taiki-e merged 4 commits intorust-lang:masterfrom Jul 29, 2021
Merged
New poll_immediate functions to immediately return from a poll#2452taiki-e merged 4 commits intorust-lang:masterfrom
taiki-e merged 4 commits intorust-lang:masterfrom
Conversation
taiki-e
requested changes
Jun 18, 2021
Member
taiki-e
left a comment
There was a problem hiding this comment.
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
Contributor
Author
|
@taiki-e I think all the checks should pass now, if you can approve the waiting workflow. |
taiki-e
reviewed
Jun 24, 2021
Member
taiki-e
left a comment
There was a problem hiding this comment.
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.
taiki-e
reviewed
Jul 29, 2021
Member
taiki-e
left a comment
There was a problem hiding this comment.
Thanks. LGTM aside from a nit.
Co-authored-by: Taiki Endo <te316e89@gmail.com>
taiki-e
pushed a commit
that referenced
this pull request
Aug 28, 2021
Merged
taiki-e
pushed a commit
that referenced
this pull request
Aug 30, 2021
Merged
Member
|
Published in 0.3.17 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 isUnpinwhich 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