Subject not found.
1.

What are Go channels and how are channels used in Golang?

Answer»

Go channel is a medium using which goroutines communicate DATA values with each other. It is a technique that allows data transfer to other goroutines. A channel can transfer data of the same type. The data transfer in the channel is bidirectional meaning the goroutines can use the same channel for sending or receiving the data as shown in the image below:

A channel can be created by adding the chan keyword as shown in the SYNTAX below:

VAR channel_name chan Type

It can also be created by using the make() FUNCTION as:

channel_name:= make(chan Type)

To send the data to a channel, we can use the <- operator as shown in the syntax:

channel_name <- element

To receive data sent by the send operator, we can use the below syntax:

element := <-Mychannel


Discussion

No Comment Found