-
Book Overview & Buying
-
Table Of Contents
Practical Systems Programming in Go
By :
In concurrent systems, coordination matters. Channels provide a built-in way for goroutines to exchange data safely by communicating directly, without relying on shared memory or explicit locking. A channel creates a synchronization point: a sender will block until a receiver is ready, and vice versa, enabling deterministic interaction between independently executing routines.
When working with channels in Go, it is important to understand how they behave once closed. If you read from a closed channel, the operation does not block; instead, it immediately returns the channel's zero value along with a Boolean indicator (ok) set to false, which you can use to detect that the channel has been closed. This makes it safe to keep receiving from a channel in a loop until it is closed. On the other hand, if you write to a closed channel, Go panics at runtime with the "send on closed channel" error. This behavior enforces the rule that channels should only...