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

Blocking thread::sleep inside an async fn #64

Open
hwchen opened this issue Nov 25, 2019 · 0 comments
Open

Blocking thread::sleep inside an async fn #64

hwchen opened this issue Nov 25, 2019 · 0 comments

Comments

@hwchen
Copy link

@hwchen hwchen commented Nov 25, 2019

I've seen several async beginners try to use thread::sleep to try to wrap their brains around async. It's probably one of the most common ways to "see" async. I just want to make sure it's addressed in the async book. (I haven't read it, but at least one of the reddit threads was lifted from the book's join example).

There's also the possibility of a clippy lint, but beginners may not have gotten there yet.

rust-lang/rust-clippy#4377

https://old.reddit.com/r/rust/comments/e1gxf8/not_understanding_asyncawait_properly/
https://old.reddit.com/r/rust/comments/dtp6z7/what_can_i_actually_do_with_the_new_async_fn/
https://old.reddit.com/r/rust/comments/dt0ruy/how_to_await_futures_concurrently/

tmandry pushed a commit that referenced this issue Sep 16, 2020
I wanted to write an example to help guide people new to asynchronous programming, with fewer external dependencies (as some people requested in #66). The example starts with the [single threaded TCP server from the Rust book](https://doc.rust-lang.org/book/ch20-01-single-threaded.html) and uses async functionality to add concurrency.
The example goes through:
- some examples of blocking code and how to make them non blocking (should address #64 as well)
- spawning tasks vs using combinators to run them concurrently on a single thread
- testing code by creating mocks and implementing async read/write traits for the mocks
huangjj27 referenced this issue in huangjj27/async-book Jan 1, 2021
I wanted to write an example to help guide people new to asynchronous programming, with fewer external dependencies (as some people requested in #66). The example starts with the [single threaded TCP server from the Rust book](https://doc.rust-lang.org/book/ch20-01-single-threaded.html) and uses async functionality to add concurrency.
The example goes through:
- some examples of blocking code and how to make them non blocking (should address #64 as well)
- spawning tasks vs using combinators to run them concurrently on a single thread
- testing code by creating mocks and implementing async read/write traits for the mocks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant