package main
import "fmt"
// write data
func writeData(intChan chan int) {
for i := 1; i <= 50; i++{
intChan <- i
fmt.Println("write data ", i)
}
close(intChan)
}
// read data
func readData(intChan chan int, exitChan chan bool) {
for {
v, ok := <- intChan
if !ok {
break
}
fmt.Printf("read data = %v\n", v)
}
exitChan <- true
close(exitChan)
}
func main() {
intChan := make(chan int, 50)
exitChan := make(chan bool, 1)
go writeData(intChan)
go readData(intChan, exitChan)
for {
_, ok := <- exitChan
if !ok {
break
}
}
}