Channel capacity is the number of values a buffered Go channel can hold before a send blocks. An unbuffered channel has capacity zero; a buffered channel has capacity of at least one. section 9.7
The second send blocks
With capacity one, the first send succeeds immediately. After the channel is full, the second send blocks until a receiver removes a value. section 9.7
Choose the channel form according to the coordination required:
- Use an unbuffered channel when the send and receive must synchronize. section 9.7
- Use a buffered channel when a sender may continue while capacity remains, remembering that buffering provides communication but not strong synchronization. section 9.7
ch1 := make(chan int) ch2 := make(chan int, 0)
Compare the equivalent zero-capacity declarations for an unbuffered channel. section 9.7
ch3 := make(chan int, 1) ch3 <-1 #1 ch3 <-2 #2
Trace how capacity one permits the first send and blocks the second. section 9.7
