GOLANG
Anatomy of Channels in Go - Concurrency in Go
What are the channels?
A channel is a communication object using which goroutines can communicate with each other. Technically, a channel is a data transfer pipe where data can be passed into or read from. Hence one goroutine can send data into a channel, while other goroutines can read that data from the same channel.
Declaring a channel
Go provides chan
keyword to create a channel. A channel can transport data of only one data type. No other data types are allowed to be transported from that channel.
Above program declares a channel c
which can transport data type of int
. Above program prints <nil>
because zero-value of a channel is nil
. But a nil
channel is not useful. You can not pass data to or read data from a channel which is nil
. Hence, we have to use make
function to create a ready-to-use channel.