When I tried to print out:
fmt.Println(c <- x)right before the for loop in the code block below to see what "c <- x" would evaluate to, it got the error message:
./select.go:7: send statement c <- x used as value; use select for non-blocking send
Is "c <- x" evaluated to true if the sending operation was successful? And why does Go only let you use the value of the send statement (aka value of "c <- x") inside case statements inside a select statement?
func fibonacci(c, quit chan int) {
x, y := 1, 1
for {
select {
case c <- x:
x, y = y, x + y
case <-quit:
fmt.Println("quit")
return
}
}
}
Thank you