...

/

Directional Nature of the Channel

Directional Nature of the Channel

Learn to use the directional nature of the channel.

Bidirectional nature of the channel

Channels are bidirectional. That is, we can both send and receive data using channels. Let’s look at the working code for a bidirectional channel. the bidirectional channel:

Press + to interact
package main
import "fmt"
func printValue(goChannel chan int) {
fmt.Println("Value inside the channel is ", <-goChannel)
goChannel <- 1
}
func main() {
goChannel := make(chan int)
go printValue(goChannel)
goChannel <- 2
fmt.Println("Value inside the channel is ", <-goChannel)
}

We can send to and receive from the printValue function ...