GO LEARNING PATH · 13 LESSONS
Concurrency
Goroutines, channel ownership, select, buffers and who may send.
An unbuffered channel is a meeting
Say what blocks, and for how long, on a channel with no buffer.
3 min · Prediction challenge
go returns nothing
Get a result out of a goroutine, and know when the program stops waiting.
3 min · Prediction challenge
Cancellation is a request; joining proves exit
Design a worker so it can stop waiting and its owner can wait for it to finish.
3 min · Worked lesson
The sender closes, the receiver ranges
Decide who closes a channel, and why the other side must not.
3 min · Worked lesson
select waits on several things; context says stop
Make a blocking operation cancellable without a flag or a kill switch.
3 min · Worked lesson
A mutex is for state; a channel is for handing over
Choose between a mutex and a channel for a given problem.
3 min · Worked lesson
The worker pool, written once
Build a fixed set of workers that finishes cleanly.
3 min · Worked lesson
More goroutines are not more capacity
Bound active workers and queued work according to the resource that actually limits throughput.
3 min · Worked lesson
A buffer is a mailbox, not a meeting
Send n values on a channel of capacity n without another goroutine.
3 min · Worked lesson
range over a channel ends when it closes
Drain a channel with range, and close it from the sender.
3 min · Worked lesson
default makes select try, not wait
Receive from a channel if a value is ready, and return if it is not.
3 min · Worked lesson
The arrow in the type is who may send
Write a producer that takes chan<- int and closes it.
3 min · Worked lesson
sync.Once runs a function one time, for everyone
Initialise shared state without a lock you have to remember.
3 min · Worked lesson