select 的使用
select {
case n = <-c1:
values = append(values, n)
case n = <-c2:
values = append(values, n)
case activeWorker <- activeValue:
values = values[1:]
case <-time.After(400 * time.Millisecond):
fmt.Println("time out...")
case <-tick:
fmt.Println("queue len:", len(values))
case <-tm:
fmt.Println("Bye...")
return

}
定时器的使用
tm := time.After(10 * time.Second)
tick := time.Tick(time.Second)
在 select 中使用 nil channel
var activeWorker chan<- int


select {
case n = <-c1:
values = append(values, n)
case n = <-c2:
values = append(values, n)
case activeWorker <- activeValue:
values = values[1:]
}