Channel types
A channel provides a mechanism for concurrently executing functions to communicate by sending and receiving values of a specified element type. The value of an uninitialized channel is
nil
.ChannelType = ( "chan" | "chan" "<-" | "<-" "chan" ) ElementType .
Channels are one of the most confusing parts of Go, for many newcomers. But they don’t need to be. They’re actually quite simple.
Think of a channel as an array, which can only be read from one end, and appended to the other.
There are a few other rules around how channels work, which we’ll of course get to, but from a data type standpoint, that serves as a useful summary.
There are no magical scoping or garbage collection rules. Channels don’t do anything. They’re just a data type. They just hold data, and they go out of scope, get garbage collected, can be passed around, assigned, re-assigned, just as any other type can.
Quotes from The Go Programming Language Specification Version of December 15, 2022