为什么这个Golang代码不能在多个时间内进行选择.
见下面的代码.永远不会发出“超时”消息.为什么?
package main import ( "fmt" "time" ) func main() { count := 0 for { select { case <-time.After(1 * time.Second): count++ fmt.Printf("tick %d\n",count) if count >= 5 { fmt.Printf("ugh\n") return } case <-time.After(3 * time.Second): fmt.Printf("timeout\n") return } } }
在Playground:http://play.golang.org/p/1gku-CWVAh上运行它
输出:
tick 1 tick 2 tick 3 tick 4 tick 5 ugh