Why doesn't this Golang code to select among multiple time.After channels work?
See code below. The 'timeout' message is never issued. Why?
package main
import (
"fmt"
"time"
)
func main() {
count := 0
for {
select {
case <-time.After(1 * time.Second):
count++
fmt.Printf("tick %d
", count)
if count >= 5 {
fmt.Printf("ugh
")
return
}
case <-time.After(3 * time.Second):
fmt.Printf("timeout
")
return
}
}
}
Run it on Playground: http://play.golang.org/p/1gku-CWVAh
Output:
tick 1
tick 2
tick 3
tick 4
tick 5
ugh