Directional Nature of the Channel
Learn to use the directional nature of the channel.
We'll cover the following...
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 mainimport "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 <- 2fmt.Println("Value inside the channel is ", <-goChannel)}
We can send to and receive from the printValue
function ...