Channel

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.

The optional operator <- specifies the direction of the channel, sending or receiving. If no direction is provided, the channel is bidirectional.


chan T // can be used to send/receive values ​​of type T
chan<- float64 // can only be used to send float64
<-chan int // can only be used to receive int
                        

A new initialized channel value can be created using the built-in function make(), which takes the channel type and an optional capability as arguments:


make(chan int, 100)
                        
channel_type.go