-
Notifications
You must be signed in to change notification settings - Fork 334
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
Added cancellation-token content in Graceful Shutdown topic docs #695
Conversation
Cancellation Tokens should be used to notify task to shut down instead of broadcast channels closes tokio-rs#694
Generally, to share a token between multiple tasks, you need to clone it. It would be good to include a bit about that. Also, I don't think your example compiles due to this issue. |
@Darksonn You are right. My example was not compiling due to ownership rule. I have included token cloning in doc and code snippet. |
content/tokio/topics/shutdown.md
Outdated
easy to implement graceful shutdowns. | ||
|
||
Note that, a `CancellationToken` can only be used by one task at a time due to | ||
ownership rule. To use the same `CancellationToken` in multiple tasks you can make |
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 grammar here is a bit awkward. How about this?
To share a cancellation token between several tasks, you must clone it. This is due to the single ownership rule that requires that each value has a single owner. When cloning a token, you get another value that's indistinguishable from the original; if one is cancelled, then the other is also cancelled. You can make as many clones as you need, and when you call
cancel
on one of them, they're all cancelled.
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, this is a good explanation. I will add this.
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.
@Darksonn I have updated the content
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.
Cancellation Tokens should be used to notify task to shut down instead of broadcast channels. Therefore, I replaced usage of Broadcast Channel in Telling things to shut down section of Graceful Shutdown topic docs with Cancellation Tokens
closes #694