I'm new to Go and i'm trying to understand why this code returns:
12
true
Heres the simple program:
package main
import "fmt"
func foo(c chan int, myValue int) {
c <- myValue * 2
}
func main() {
c := make(chan int)
go foo(c, 3)
go foo(c, 6)
v1, v2 := <-c
fmt.Println(v1)
fmt.Println(v2)
}
Is it true just because it gets some random value back?
The second value in a two value receive assigment is a boolean reporting whether the communication succeeded. The value v1
is the value received from the channel. The value v2
is true because communication succeeded.