package main import ( "fmt" "time" ) func producer(chnl chan int) { for i := 0; i < 10; i++ { time.Sleep(100 * time.Millisecond) chnl <- i } close(chnl) } func outer(chn2 chan int) { for i := 10; i < 100; i++ { chn2 <- i } close(chn2) } func main() { ch, ch2 := make(chan int), make(chan int) go producer(ch) go outer(ch2) for { v, ok := <-ch if ok == false { v, ok2 := <-ch2 if ok2 == false { break } fmt.Println("Received2 ", v, ok) continue } fmt.Println("Received ", v, ok) } ch3 := make(chan int) go producer(ch3) for v := range ch3 { fmt.Println("Received ", v) } }