I just started to learn Go Language, and I'm enjoying writing code in Go.
So today, I'm trying to understand how the unbuffered channel works
Can someone help me to understand why this code is not working. I'm expecting that <-ch wait until we receive from channel ch
func main() {
ch := make(chan struct{})
ch2 := make(chan int)
go func() {
arr := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
for _, v := range arr {
ch2 <- v
}
}()
go func() {
for t := range ch2 {
fmt.Println(t)
}
ch <- struct{}{}
}()
<-ch
}
Thanks & Regards
Manjeet Thakur