-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
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.
Hi. Thank you for the PR. Please see CONTRIBUTING.md
for instructions for fixing the CI issue.
tokio/src/task/blocking.rs
Outdated
/// 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) |
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.
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.
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 Sure, I can split the URL. Also, is the following correct then -
Runs the provided function on the executor reserved for blocking operations
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.
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?
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.
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 ?
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.
Did you miss up your clipboard?
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.
Yes, I did not run rustfmt
before sending it. I will correct this and send it. Is the above comment okay though?
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.
I was referring to the "It can be thought of as an efficient iterator for collections of bytes." part.
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 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
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.
Sure, looks good. Perhaps add an empty line between each pair of lines.
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.
I will send the PR right away. Thanks !
458db38
to
908f131
Compare
tokio/src/task/blocking.rs
Outdated
/// 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. |
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.
Can we fix the duplicated line?
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.
I have fixed it.
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.
It is not running on a separate executor, but a thread on the same executor. I would rather swap them the other way.
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.
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."
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.
Okay, I will commit the final change
f524362
to
dc03b55
Compare
tokio/src/task/blocking.rs
Outdated
@@ -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 |
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.
If we fix the typo here, I think this is ready to merge :)
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.
lol!
I don't know why I am making so many mistakes. Sorry for the troubles.
bc4f2b5
to
ecef736
Compare
tokio/src/task/blocking.rs
Outdated
@@ -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. |
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 block_in_place
function works differently from spawn_blocking
. It doesn't run it on a separate thread.
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.
Sorry about that. I am making the change. I modified the wrong function by mistake.
ecef736
to
b9b4e9b
Compare
@Darksonn I think the PR is ready for merge. |
CI is still running. I will do it tomorrow. |
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.