Skip to content
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

doc: improves spawn_blocking documentation #2426

Merged
merged 1 commit into from
Apr 23, 2020

Conversation

palashahuja
Copy link
Contributor

The initial spawn_blocking documentation was unclear. This PR attempts to fix that.

Fixes #2143

Solution

Wrote a simpler documentation since the initial blocking documentation was unclear.

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Hi. Thank you for the PR. Please see CONTRIBUTING.md for instructions for fixing the CI issue.

Comment on lines 42 to 44
/// Spawns a blocking thread on the currently provided executor.
/// More information about the blocking threads is available at
/// [CPU-bound tasks and blocking code](../index.html#cpu-bound-tasks-and-blocking-code)
Copy link
Contributor

Choose a reason for hiding this comment

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

It does not necessarily spawn a thread. The threads are reused. Additionally, can you split the link and url with this syntax:

at [CPU-bound tasks and blocking code][blocking].

[blocking]: ../index.html#cpu-bound-tasks-and-blocking-code

You're also missing a period at the end of the sentence.

Copy link
Contributor Author

@palashahuja palashahuja Apr 22, 2020

Choose a reason for hiding this comment

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

@Darksonn Sure, I can split the URL. Also, is the following correct then -
Runs the provided function on the executor reserved for blocking operations

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, it's part of the same executor as the async code.. I quite like the phrasing in the sentence above: "It can be thought of as an efficient Iterator for collections of bytes." Perhaps you can merge the two lines together?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. So, this is the final comment -

Runs the provided function on the executor reserved for blocking operations. 
It can be thought of as an efficient iterator for collections of bytes. 
More information about the blocking threads is available at [CPU-bound tasks and blocking code][blocking].
[blocking]: ../index.html#cpu-bound-tasks-and-blocking-code

Is this okay @Darksonn ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you miss up your clipboard?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I did not run rustfmt before sending it. I will correct this and send it. Is the above comment okay though?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was referring to the "It can be thought of as an efficient iterator for collections of bytes." part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh okay!
I meant this

Runs the provided function on the executor reserved for blocking operations. 
More information about the blocking threads is available at [CPU-bound tasks and blocking code][blocking].
[blocking]: ../index.html#cpu-bound-tasks-and-blocking-code

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, looks good. Perhaps add an empty line between each pair of lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will send the PR right away. Thanks !

/// yielding is not okay, as it may prevent the executor from driving other futures forward.
/// A closure that is run through this method will instead be run on a dedicated thread pool for
/// such blocking tasks without holding up the main futures executor.
/// Runs the provided function on the executor reserved for blocking operations.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we fix the duplicated line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have fixed it.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is not running on a separate executor, but a thread on the same executor. I would rather swap them the other way.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've just realized that it was I who messed up my clipboard previously. When I said "It can be thought of as an efficient Iterator for collections of bytes.", I was trying to say "Runs the provided closure on a thread where blocking is acceptable."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I will commit the final change

@palashahuja palashahuja force-pushed the doc_blocking branch 3 times, most recently from f524362 to dc03b55 Compare April 22, 2020 18:37
@@ -37,12 +37,11 @@ cfg_rt_threaded! {
}

cfg_blocking! {
/// Runs the provided closure on a thread where blocking is acceptable.
/// Runs the provided closue on a thread where blocking is acceptable
Copy link
Contributor

Choose a reason for hiding this comment

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

If we fix the typo here, I think this is ready to merge :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol!
I don't know why I am making so many mistakes. Sorry for the troubles.

@palashahuja palashahuja force-pushed the doc_blocking branch 2 times, most recently from bc4f2b5 to ecef736 Compare April 22, 2020 18:42
@@ -1,7 +1,7 @@
use crate::task::JoinHandle;

cfg_rt_threaded! {
/// Runs the provided blocking function without blocking the executor.
/// Runs the provided closure on a thread where blocking is acceptable.
Copy link
Contributor

Choose a reason for hiding this comment

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

The block_in_place function works differently from spawn_blocking. It doesn't run it on a separate thread.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about that. I am making the change. I modified the wrong function by mistake.

@palashahuja
Copy link
Contributor Author

@Darksonn I think the PR is ready for merge.

@Darksonn
Copy link
Contributor

CI is still running. I will do it tomorrow.

@Darksonn Darksonn merged commit f83f638 into tokio-rs:master Apr 23, 2020
@palashahuja palashahuja deleted the doc_blocking branch April 23, 2020 14:56
@Darksonn Darksonn added A-tokio Area: The main tokio crate C-maintenance Category: PRs that clean code up or issues documenting cleanup. M-task Module: tokio/task T-docs Topic: documentation labels Apr 29, 2020
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 C-maintenance Category: PRs that clean code up or issues documenting cleanup. M-task Module: tokio/task T-docs Topic: documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tokio::spawn_blocking has slightly misleading documentation
2 participants