In this video, we are going to be looking at Channels in Go and what they are used for.
Overview
package main
import (
"fmt"
"math/rand"
)
func CalculateValue(values chan int) {
value := rand.Intn(10)
fmt.Printf("Value Calculated: %d\n", value)
values <- value
}
func main() {
values := make(chan int)
go CalculateValue(values)
value := <-values
fmt.Println(value)
}
Output
$ go run main.go
Value Calculated: 1
1