Skip to content

Conversation

samugi
Copy link
Contributor

@samugi samugi commented Oct 8, 2025

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 with block_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

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 ADD-SP added T-docs Topic: documentation A-tokio Area: The main tokio crate M-runtime Module: tokio/runtime labels Oct 8, 2025
Copy link
Member

@ADD-SP ADD-SP left a 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.

@ADD-SP ADD-SP added the S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author. label Oct 8, 2025
@samugi samugi requested a review from ADD-SP October 9, 2025 07:16
/// # }
/// ```
///
/// `Handle::block_on` may use [`task::block_in_place`] to re-enter the async context of a multi-thread scheduler runtime:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks

Copy link
Member

@ADD-SP ADD-SP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ADD-SP ADD-SP changed the title docs: clarify Handle::block_on behavior with block_in_place runtime: clarify Handle::block_on behavior with block_in_place Oct 10, 2025
@ADD-SP ADD-SP changed the title runtime: clarify Handle::block_on behavior with block_in_place runtime: clarify the behavior of Handle::block_on Oct 10, 2025
@ADD-SP ADD-SP merged commit ad6f618 into tokio-rs:master Oct 10, 2025
88 checks passed
@Darksonn Darksonn mentioned this pull request Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tokio Area: The main tokio crate M-runtime Module: tokio/runtime S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author. T-docs Topic: documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs: block_on should mention block_in_place

3 participants