Rob Pike's examples from Go Concurrency Patterns, but in Rust.
All examples use the async-std and futures crates, except where standard threads are used to demonstrate contrasting behaviour.
Initially this was a learning exercise for me. Back when I first started learning Go, Rob's talk really helped me get a good intuition for go-routines and channels. I wanted to compare Rust's approach to asynchrony by relating back to what I already understood from Go.
The complexity of the examples increases at a comfortable pace. Each builds on the knowledge gained in those that came before.
This was a really good practical way to learn Rust's async features and libraries, without the burden of needing to build an actual application at the same time.
I highly recommend this as an exercise for others.
Each example is documented using rustdoc comments, with text from Rob's original slides adapted for Rust.
Instructions for running and browsing follow:
- Run:
cargo run --bin 01_boring
- View source
- Run:
cargo run --bin 02_boring_rand_sleep
- View source
- Run:
cargo run --bin 03_ignore
- View source
- Run:
cargo run --bin 04_ignore_less
- View source
- Run:
cargo run --bin 05_channel
- View source
- Run:
cargo run --bin 06_generator_function
- View source
- Run:
cargo run --bin 07_channels_as_handle_on_svc
- View source
- Run:
cargo run --bin 08_1_fan_in_multiplexing
- View source
- Run:
cargo run --bin 08_2_fan_in_restoring_sequence
- View source
- Run:
cargo run --bin 08_3_fan_in_with_select
- View source
- Run:
cargo run --bin 09_1_timeout_select
- View source
- Run:
cargo run --bin 09_2_timeout_combinator
- View source
- Run:
cargo run --bin 10_1_timeout_conversation_select
- View source
- Run:
cargo run --bin 10_2_timeout_conversation_combinator
- View source
- Run:
cargo run --bin 11_1_quit_channel
- View source
- Run:
cargo run --bin 11_2_quit_channel_wait_for_done
- View source
- Run:
cargo run --bin 12_daisy_chain_thread_limit
- View source
- Run:
cargo run --bin 12_daisy_chain_unlimited
- View source
- Run:
cargo run --bin 13_1_fake_google_search
- View source
- Run:
cargo run --bin 13_2_fake_google_search_async
- View source
- Run:
cargo run --bin 13_3_fake_google_search_timeout
- View source
TODO I'm still to complete this.
To generate rustdoc
HTML documentation:
cargo doc --bins --no-deps
Then open target/doc/01_boring/index.html in your browser.