Why does not the channel c buffered out when the second value is sent via another go routine and the first value sent isn't received?
package main
import "fmt"
func sum(s []int, c chan int) {
sum := 0
for _, v := range s {
sum += v
}
c <- sum // send sum to c
}
func main() {
s := []int{7, 2, 8, -9, 4, 0}
c := make(chan int)
go sum(s[:len(s)/2], c)
go sum(s[len(s)/2:], c)
x, y := <-c ,<-c// receive from c
fmt.Println(x,y ,x+y)
}
What I was expecting is an error-
fatal error: all goroutines are asleep - deadlock!
This occurs when there is a block when the buffer is full. Since channel c has size 1, sending the second value should have given the above error.
What is happening in above code ?