Control concurrent Go work with contexts
8 steps · about 4 h 25 min · Intermediate
- Model independent concurrent work (reference, Go documentation, 35 min)
Use goroutines and communication to express tasks that can make progress independently.
- Propagate cancellation with context (reference, Go package documentation, 35 min)
Carry deadlines and cancellation across API boundaries without inventing a parallel mechanism.
- Design context-aware functions (reference, The Go Blog, 30 min)
Accept context explicitly and stop work promptly when the request is no longer useful.
- Communicate through channels (reference, A Tour of Go, 30 min)
Transfer values and synchronise progress while understanding when sends and receives block.
- Select cancellation or progress (reference, A Tour of Go, 30 min)
Wait on multiple operations so cancellation cannot be hidden behind a blocked channel action.
- Wait for goroutine completion (reference, Go package documentation, 25 min)
Make ownership of goroutine shutdown visible and prevent the caller from returning too early.
- Prevent pipeline leaks (guide, Go documentation, 40 min)
Close owned channels and ensure upstream workers can exit when downstream stops reading.
- Test cancellation and races (reference, Go documentation, 40 min)
Exercise completion, timeout and early-cancel paths under the race detector and leak-sensitive assertions.