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.

Start: step 1

6 steps · a step counts once you play it to the end

  1. Why didn't my goroutines run?Go · Basicsmain starts three goroutines and returns. None of them get to print.
  2. 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.
  3. A worker pool on a channelGo · IntermediateTwo workers range over a jobs channel. close(jobs) tells them no more jobs are coming.
  4. A select timeout that leaks a goroutineGo · IntermediateThe timeout wins, but slowCall's goroutine is left stuck on its send, forever.
  5. Stopping goroutines with context cancellationGo · IntermediateThree workers share one context. A single cancel() wakes every select watching ctx.Done(), and all three stop.
  6. 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.

All learning paths · All scenarios