Channel Size is One or None

Channels should usually have a size of one or be unbuffered. By default,channels are unbuffered and have a size of zero. Any other sizemust be subject to a high level of scrutiny. Consider how the size isdetermined, what prevents the channel from filling up under load and blockingwriters, and what happens when this occurs.

BadGood
  1. // Ought to be enough for anybody!
  2. c := make(chan int, 64)
  1. // Size of one
  2. c := make(chan int, 1) // or
  3. // Unbuffered channel, size of zero
  4. c := make(chan int)