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

task: Add more tips + links to spawn_blocking docs #4150

Merged
merged 2 commits into from Oct 26, 2021

Conversation

cgwalters
Copy link
Contributor

@cgwalters cgwalters commented Oct 4, 2021

I'm working on some code which heavily uses spawn_blocking
to run synchronous code, and it took me a while to find and understand
the relevant APIs and patterns here.

First, basically no real world case will spawn
a closure that takes no parameters, so
change the first example to pass an input value, mutate it, and
receive the result.

Let's link to the channel blocking APIs, and provide a small example
of that too.

This also mentions SyncIoBridge now.


tokio/src/task/blocking.rs Outdated Show resolved Hide resolved
tokio/src/task/blocking.rs Outdated Show resolved Hide resolved
@Darksonn Darksonn added A-tokio Area: The main tokio crate M-blocking Module: tokio/task/blocking T-docs Topic: documentation labels Oct 4, 2021
@Darksonn
Copy link
Contributor

Darksonn commented Oct 5, 2021

The CI failure is because your PR is written on top of an old master from May.

@cgwalters cgwalters marked this pull request as draft October 5, 2021 14:34
@cgwalters
Copy link
Contributor Author

OK I updated this and also added a link to the result from #4146 - so marking draft until that merges.

I'm working on some code which heavily uses `spawn_blocking`
to run synchronous code, and it took me a while to find and understand
the relevant APIs and patterns here.

First, basically no real world case will spawn
a closure that takes no parameters, so
change the first example to pass an input value, mutate it, and
receive the result.

Let's link to the channel blocking APIs, and provide a small example
of that too.

This also mentions `SyncIoBridge` now.
@cgwalters cgwalters marked this pull request as ready for review October 26, 2021 15:18
@cgwalters
Copy link
Contributor Author

cgwalters commented Oct 26, 2021

OK rebased 🏄 and now links to the SyncIOBridge from #4146

Specifically related to this subthread - I would say that the existing bridging toplevel doc is actually mostly about the inverse case of creating a tokio runtime for a portion of a largely synchronous codebase, whereas the goal of this PR is to help explain how to use some synchronous code inside a largely asynchronous codebase.

I created tokio-rs/website#621 to link back to this one.

tokio/src/task/blocking.rs Outdated Show resolved Hide resolved
@Darksonn Darksonn merged commit 268ed5e into tokio-rs:master Oct 26, 2021
oliver-giersch pushed a commit to oliver-giersch/tokio that referenced this pull request Oct 28, 2021
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-blocking Module: tokio/task/blocking T-docs Topic: documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants