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.


@cgwalters cgwalters force-pushed the more-spawn-blocking-docs branch from f06a068 to 0f7b2cf Compare Oct 4, 2021
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 M-blocking T-docs 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 Oct 5, 2021
@cgwalters
Copy link
Contributor Author

cgwalters commented Oct 5, 2021

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 force-pushed the more-spawn-blocking-docs branch from e2d1642 to 0bacb79 Compare Oct 26, 2021
@cgwalters cgwalters marked this pull request as ready for review Oct 26, 2021
@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
27 checks passed
oliver-giersch pushed a commit to oliver-giersch/tokio that referenced this issue Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio M-blocking T-docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants