Skip to content

Latest commit

 

History

History
160 lines (98 loc) · 4.36 KB

README.md

File metadata and controls

160 lines (98 loc) · 4.36 KB

Go concurrency patterns in Rust

What?

Rob Pike's examples from Go Concurrency Patterns, but in Rust.

How?

All examples use the async-std and futures crates, except where standard threads are used to demonstrate contrasting behaviour.

Why?

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.

Running and browsing the examples

Each example is documented using rustdoc comments, with text from Rob's original slides adapted for Rust.

Instructions for running and browsing follow:

01_boring

02_boring_rand_sleep

  • Run: cargo run --bin 02_boring_rand_sleep
  • View source

03_ignore

04_ignore_less

05_channel

06_generator_function

  • Run: cargo run --bin 06_generator_function
  • View source

07_channels_as_handle_on_svc

  • Run: cargo run --bin 07_channels_as_handle_on_svc
  • View source

08_1_fan_in_multiplexing

  • Run: cargo run --bin 08_1_fan_in_multiplexing
  • View source

08_2_fan_in_restoring_sequence

  • Run: cargo run --bin 08_2_fan_in_restoring_sequence
  • View source

08_3_fan_in_with_select

  • Run: cargo run --bin 08_3_fan_in_with_select
  • View source

09_1_timeout_select

09_2_timeout_combinator

  • Run: cargo run --bin 09_2_timeout_combinator
  • View source

10_1_timeout_conversation_select

  • Run: cargo run --bin 10_1_timeout_conversation_select
  • View source

10_2_timeout_conversation_combinator

  • Run: cargo run --bin 10_2_timeout_conversation_combinator
  • View source

11_1_quit_channel

11_2_quit_channel_wait_for_done

  • Run: cargo run --bin 11_2_quit_channel_wait_for_done
  • View source

12_daisy_chain_thread_limit

  • Run: cargo run --bin 12_daisy_chain_thread_limit
  • View source

12_daisy_chain_unlimited

  • Run: cargo run --bin 12_daisy_chain_unlimited
  • View source

13_1_fake_google_search

  • Run: cargo run --bin 13_1_fake_google_search
  • View source

13_2_fake_google_search_async

  • Run: cargo run --bin 13_2_fake_google_search_async
  • View source

13_3_fake_google_search_timeout

  • Run: cargo run --bin 13_3_fake_google_search_timeout
  • View source

13_4_fake_google_search_replication

TODO I'm still to complete this.

Browsing the docs for the examples as rustdoc

To generate rustdoc HTML documentation:

cargo doc --bins --no-deps

Then open target/doc/01_boring/index.html in your browser.