package main
import (
"log"
"time"
)
func add(ch chan<- string) {
for {
time.Sleep(time.Second * 2)
ch <- "hi"
}
}
func exit(ch chan<- string) {
time.Sleep(time.Second * 5)
ch <- "close"
}
func main() {
ch := make(chan string, 1000)
go add(ch)
go exit(ch)
LOOP:
for {
select {
case val := <- ch:
switch val {
case "close":
log.Println("Close")
break LOOP
case "hi":
log.Println("Hi")
}
default:
log.Println("Default")
time.Sleep(time.Second * 1)
}
}
}