-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
Description
http://play.golang.org/p/9saBM6ph-9
There seems to be a small delay incurred when Timer starts. Note the "sync" workaround in notBroken. This behavior was noticed on go1.2.1 linux/amd64 and is repeatable on play.golang.org and go1.4.1 linux/amd64.
The following program outputs:
This is the undesired behavior.
This is the desired select.
package main
import "time"
func main() {
broken()
println()
notBroken()
}
func broken() {
t := time.NewTimer(0 * time.Second)
select {
case _ = <-t.C:
println("This is the desired select.")
default:
println("This is the undesired behavior.")
}
}
func notBroken() {
t := time.NewTimer(0 * time.Second)
sync := time.NewTimer(0 * time.Second)
_ = <-sync.C
select {
case _ = <-t.C:
println("This is the desired select.")
default:
println("This does not get selected.")
}
}