Channels

Passing values between goroutines

Goroutines run concurrently β€” but they need to hand results back. A walker-search goroutine finds three matches; how does it deliver them to main? The Go answer is a channel: a typed pipe that connects goroutines. One goroutine sends a value in, another receives it out.

Go's guiding proverb: "Don't communicate by sharing memory; share memory by communicating." Instead of two goroutines poking at the same variable behind a lock, one sends the value down a channel to the other. The channel handles the hand-off safely.