go-concurrency101/basics/default-select/main.go

26 lines
331 B
Go

package main
import (
"log"
"time"
)
func main() {
tick := time.Tick(100 * time.Millisecond)
boom := time.After(5000 * time.Millisecond)
for {
select {
case <-tick:
log.Println("tick.")
case <-boom:
log.Println("boom")
return
default:
log.Println(" .")
time.Sleep(50 * time.Millisecond)
}
}
}