-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Impl tokio_util::sync::WaitForCancellationFutureOwned
#5153
Merged
Darksonn
merged 19 commits into
tokio-rs:master
from
NobodyXu:impl-WaitForCancellationFutureOwned
Nov 21, 2022
Merged
Impl tokio_util::sync::WaitForCancellationFutureOwned
#5153
Darksonn
merged 19 commits into
tokio-rs:master
from
NobodyXu:impl-WaitForCancellationFutureOwned
Nov 21, 2022
Conversation
This file contains 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
Darksonn
reviewed
Nov 1, 2022
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.
I'm rather uncomfortable with adding an implementation that looks like this.
Darksonn
reviewed
Nov 15, 2022
Darksonn
reviewed
Nov 21, 2022
Darksonn
reviewed
Nov 21, 2022
Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
for field `future`. Since `Notified` does not implemented `Unpin`, it must not be moved but `do_drop` and `poll` moves it. Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
…o_drop_future` Signed-off-by: Jiahao XU <[email protected]>
to cast `Notified` to `Notified<'a>` where `'a` is the lifetime of `&'a mut self`. Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Co-authored-by: Alice Ryhl <[email protected]>
…fied` and remove the `Option<T>` wrapper. Signed-off-by: Jiahao XU <[email protected]>
Co-authored-by: Alice Ryhl <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Darksonn
reviewed
Nov 21, 2022
Co-authored-by: Alice Ryhl <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Darksonn
approved these changes
Nov 21, 2022
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.
Looks good to me. Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
Signed-off-by: Jiahao XU [email protected]
Motivation
tokio_util::sync::WaitForCancellationFuture
takes a reference to theCancellationToken
, which is hard to use instruct
s where you don't want a lifetime.Solution
tokio_util::sync::WaitForCancellationFutureOwned
provides an alternative whereCancellationToken
is taken by value so thatWaitForCancellationFutureOwned
does not contain any lifetime (but self-referenced) and can be used without worrying about lifetime.Alternatives
User use ouroboros to create self-reference struct, but it is not zero-cost.
Other self-reference crates that are zero-cost are experimental (e.g. self-reference).
Or the user can do:
which isn't zero-cost since it requires one extra allocation and also a pointer to vtable for the trait
Future
.User could also uses a
SmallBox
with pre-allocated space on stack to store the future, though it's more complicated and not zero-cost either (extra pointer to vtable and it might incur heap allocation if the pre-allocated space on stack is too small).Fixes: #4466