Go Sync or Go Home
summary
Walks through concrete uses of the standard sync and x/sync packages and shows working code: a file-transfer function that uses errgroup.WithContext to propagate the first error, cancel remaining sends and limit goroutines; and a cached token authenticator that uses singleflight.Do/DoChan to suppress duplicate auth calls, reduce network and cache churn. Errgroup is imported by about 12,000 packages, singleflight by ~1,215. Also covers Pool, RWMutex, WaitGroup, sync.Map, Cond (discouraged) and singleflight Forget and generics wrappers.
AI-written summary · about
chapters (11)
- 0:00Concurrency in Go
- 2:58Synchronization tools
- 5:23Using WaitGroup
- 6:45Error groups
- 8:25Context and limits
- 10:36Singleflight basics
- 13:37Caching with singleflight
- 17:40Singleflight Do method
- 20:30Singleflight DoChan
- 23:00Sync.Cond and alternatives
- 25:48Finding Go packages
related talks
43mDeep dive into the sync package
16mIn the land of Gophers from age 3
28mIdiomatic Go Tricks
35m"Rush Tactics: Writing Go Code You Won’t Regret Later"
30mUnraveling Go Anti-Patterns
26mConcurrency primitives of Golang - how to use and how not to
31mGoroutines and Cells: Lessons in Goal-Directed Systems
24mMastering Concurrency in Go: From Patterns to Production
