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

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/036af456-f499-4b5d-8c78-33b696edaa7bn%40googlegroups.com.

Reply via email to