How do channels work

Channels are typed conduits for safe communication between goroutines using send and receive operations.

Channels are typed conduits that let goroutines communicate by sending and receiving values, blocking until both sides are ready. Use make to create a channel, the <- operator to send or receive, and close to signal completion.

ch := make(chan int)

// Sender (in a goroutine)
ch <- 42

// Receiver
value := <-ch

// Close when done
close(ch)