[ Home ]

Go Channels/Select

I've been reading parts of Katherine Cox-Buday's Concurrency in Go, and I think this incomplete list of facts about channels and select statements is useful. A full table of channel operation/state/result is on page 75; these notes are just for me and whoever else may find them useful

Channels

  • a write to a full channel blocks until the channel is read from
  • a read from an empty channel blocks until the channel is writen to
  • a closed channel can be read from an infinite number of times
  • a write to a closed channel panics

Select Statements

  • all reads/writes are considered simultaneously for readiness
  • when no channels are ready, the entire select statement blocks
  • when more than one channel is ready, one will be chosen at random
  • defualt, if present, is run when all channels are blocked