Skip to content

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

Merged
Darksonn merged 2 commits intotokio-rs:masterfrom
cgwalters:more-spawn-blocking-docs
Oct 26, 2021
Merged

task: Add more tips + links to spawn_blocking docs#4150
Darksonn merged 2 commits intotokio-rs:masterfrom
cgwalters:more-spawn-blocking-docs

Conversation

@cgwalters
Copy link
Copy Markdown
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 October 4, 2021 13:16
Comment thread tokio/src/task/blocking.rs Outdated
Comment thread tokio/src/task/blocking.rs Outdated
@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
Copy Markdown
Member

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
Copy Markdown
Contributor Author

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

@cgwalters cgwalters force-pushed the more-spawn-blocking-docs branch from 0f7b2cf to e2d1642 Compare October 5, 2021 14:50
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 October 26, 2021 15:17
@cgwalters cgwalters marked this pull request as ready for review October 26, 2021 15:18
@cgwalters
Copy link
Copy Markdown
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.

Comment thread tokio/src/task/blocking.rs Outdated
@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.

2 participants