package main
import (
"fmt"
"time"
)
func main() {
a := make(chan int)
go func() {
time.Sleep(5 * time.Second)
a <- 1
}()
for {
time.Sleep(1 * time.Second)
select {
case <-a:
fmt.Println(1)
case <-time.After(1 * time.Second):
fmt.Println(2)
default:
fmt.Println(3)
}
}
}
执行上面一段代码,最终的结果只会出现1和3,永远都不会出现2