Learning paths / Go concurrency in six steps
Go concurrency in six steps
Goroutines, channels, a worker pool, timeouts, cancellation, and the leak they can cause together.
- Why didn't my goroutines run?Go · Basicsmain starts three goroutines and returns. None of them get to print.
- Does a channel send wait for the receiver?Go · BasicsOn an unbuffered channel, main's send waits until the receiver is ready to take the value.
- A worker pool on a channelGo · IntermediateTwo workers range over a jobs channel. close(jobs) tells them no more jobs are coming.
- A select timeout that leaks a goroutineGo · IntermediateThe timeout wins, but slowCall's goroutine is left stuck on its send, forever.
- Stopping goroutines with context cancellationGo · IntermediateThree workers share one context. A single cancel() wakes every select watching ctx.Done(), and all three stop.
- Goroutine leak: a blocked send after ctx.Done()Go · IntermediateEach handler gives up on ctx.Done(), but its worker still sends on an unbuffered channel nobody reads. Three cancelled requests leave three goroutines stuck forever.