runtime: clarify the behavior of Handle::block_on#7665
Merged
ADD-SP merged 3 commits intotokio-rs:masterfrom Oct 10, 2025
Merged
runtime: clarify the behavior of Handle::block_on#7665ADD-SP merged 3 commits intotokio-rs:masterfrom
Handle::block_on#7665ADD-SP merged 3 commits intotokio-rs:masterfrom
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
ADD-SP
reviewed
Oct 8, 2025
Member
ADD-SP
left a comment
There was a problem hiding this comment.
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
Darksonn
reviewed
Oct 9, 2025
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: |
Member
There was a problem hiding this comment.
Suggested change
| /// `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: |
Member
There was a problem hiding this comment.
Oh, also reflow the text with a line break at 80 or 100 chars (whatever the rest of the file is using).
apply maintainer suggestion
Handle::block_on behavior with block_in_placeHandle::block_on behavior with block_in_place
Handle::block_on behavior with block_in_placeHandle::block_on
Merged
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.
Motivation
See: #7387
Solution
This commit adds documentation to the
Handle::block_onmethod to clarify its behavior when called from within a Tokio runtime's asynchronous context, and how it can be used along withblock_in_placeto 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