ch1 := make(chan string) fmt.Println("1@", time.Now()) for { select { case <-ch1: fmt.Println("2@", time.Now()) case <-time.After(time.Second * 3): fmt.Println("3@", time.Now()) return } }
1@ 2015-03-19 15:21:45.0547549 +0800 CST
2@ 2015-03-19 15:21:46.0548121 +0800 CST
3@ 2015-03-19 15:21:49.0569838 +0800 CST
ch := make(chan string) select { case ch <- "hello": fmt.Println("send") default: fmt.Println("nothing") }
nothing
有疑问加站长微信联系(非本文作者)