-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 drop guard for cancellation token #3839
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.
Besides the doc-comment, this seems fine to me.
/// Returns a `DropGuard` for this token. | ||
pub fn drop_guard(self) -> DropGuard { |
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.
The documentation could be improved.
Any updates on this? |
/// Returns a `DropGuard` for this token. | ||
/// This guard will cancel this token (and all its children) | ||
/// on drop unless disarmed. |
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.
Newlines in doc-comments do not translate to newlines in the generated documentation unless there is an empty line.
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.
Yeah, i just dislike long lines :)
Do you think splitting first sentence into a separate paragraph makes sense?
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.
Sure.
Generally, we wrap documentation at 80 chars to avoid long lines.
Motivation
Usually, cancellation is implemented as dropping a future. However, this does not work when a future internally spawns background tasks.
Solution
A new method
drop_guard
is added. It returns a special guard which cancels the token unless disarmed.Intended usage: