This repo demos for golang concurrency patterns after read Concurrency in Go. There are something I modified in these examples.
- Buffered or unbuffered channel both are okay, it doesn't have effect in these examples. But for memory efficiency, I choose unbuffered channel.
- I reorder the pattern for easily learning based on my opinion. So there might be some differences between repo and book.
- In each example, it will print
expected 1 goroutine, got goroutine: 1
. That means the program close all goroutines safely (except main goroutine) to avoid goroutine leaks.
There is an simple introduction article written in Chinese. Feel free to read it.
Concurrency Pattern |
---|
01: Generator |
02: Done channel |
03: Pipeline |
04: Fan-In |
05: Fan-Out |
06: Fan-In and Fan-Out |
07: Or-Channel |
08: Or-Done-Channel |
09: Tee-Channel |
10: Bridge-Channel |
These examples are built with above related concepts.
Other Usage |
---|
01: Graceful Shutdown |
02: Pub/Sub |
03: Worker Pool |