-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
runtime: clarify the behavior of Handle::block_on
#7665
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
runtime: clarify the behavior of Handle::block_on
#7665
Conversation
This commit adds documentation to the `Handle::block_on`` method to clarify its behavior when called from within a Tokio runtime's asynchronous context, and how it can be used along with `block_in_place` to re-enter the runtime. closes tokio-rs#7387
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.
Just two minor comments, I personally always prefer short comment, which helps downstream user (like me) to grasp the guide in 10 seconds.
apply maintainer's suggestions
tokio/src/runtime/handle.rs
Outdated
/// # } | ||
/// ``` | ||
/// | ||
/// `Handle::block_on` may use [`task::block_in_place`] to re-enter the async context of a multi-thread scheduler runtime: |
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.
/// `Handle::block_on` may use [`task::block_in_place`] to re-enter the async context of a multi-thread scheduler runtime: | |
/// `Handle::block_on` may be combined with [`task::block_in_place`] to re-enter the async context of a multi-thread scheduler runtime: |
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.
Oh, also reflow the text with a line break at 80 or 100 chars (whatever the rest of the file is using).
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.
done, thanks
apply maintainer suggestion
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!
Handle::block_on
behavior with block_in_place
Handle::block_on
behavior with block_in_place
Handle::block_on
behavior with block_in_place
Handle::block_on
Motivation
See: #7387
Solution
This commit adds documentation to the
Handle::block_on
method to clarify its behavior when called from within a Tokio runtime's asynchronous context, and how it can be used along withblock_in_place
to re-enter the runtime.Note: the issue proposes updating the Cannot start a runtime from within a runtime error message. I chose not to change it here, since a more detailed explanation would make the message too verbose. I'm happy to adjust it if maintainers think it's worth including in this PR.
closes: #7387