when used the select word ,sometimes it may be blocked ,we can use the timer to prevent form being blocking
which used as follows:
1 package main 2 3 import ( 4 "fmt" 5 "time" 6 ) 7 8 func main() { 9 c := make(chan int) 10 o := make(chan bool) 11 go func() { 12 for { 13 select { 14 case v := <-c: 15 fmt.Println("result is ", v) 16 case a := <-time.After(5 * time.Second): 17 fmt.Println("time out", a) 18 o <- true 19 break 20 } 21 } 22 }() 23 24 <-o 25 }