Continuing with our lockdown learning of Go language. Here’s a video where we discuss Exchanging data using Channels in Golang
package main
import "fmt"
func main() {
channel := make(chan int)
//Let's square a number in a goroutine
//Pass the number to the goroutine using channel
go squareNum(channel)
channel <- 5
x := <- channel
fmt.Println("Squared", x)
//Let's increment the squared number in a goroutine
go incrementNum(channel)
channel <- x
fmt.Println("Incremented", <- channel)
}
func incrementNum(channel chan int) {
num := <- channel
num += 1
channel <- num
}
func squareNum(channel chan int) {
num := <- channel
num *= num
channel <- num
}
You can watch other videos in Go lang in the links below