package main
import "fmt"
//import "time"
func loop_in(num int, ch chan int) {
fmt.Printf("I'm the %d goroutine!!!\n", num)
for i:=1; i<=5; i++ {
ch <- i
fmt.Println(i)
}
close(ch)
}
func loop_out(num int, ch chan int, ch_out chan bool) {
fmt.Printf("I'm the %d goroutine!!!\n", num)
for {
temp, ok := <- ch
if !ok {
break
}
fmt.Printf("I'm the %d goroutine! and print %d!\n", num, temp)
}
ch_out <- true
close(ch_out)
}
func main() {
ch := make(chan int, 1)
ch_out := make(chan bool, 1)
go loop_in(1, ch)
go loop_out(2, ch, ch_out)
//temp := <- ch
//fmt.Println(temp)
//close(ch)
//<- ch_out
v, ok := <- ch_out
fmt.Println("it's over. ", v, ok)
}