example using a default statement in a select to sidestep blocking
This commit is contained in:
parent
e3bfba2430
commit
80fd57a3bc
23
concurrency/default-select/go.go
Normal file
23
concurrency/default-select/go.go
Normal file
@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
tick := time.Tick(time.Second)
|
||||
boom := time.After(time.Second * 10)
|
||||
for {
|
||||
select {
|
||||
case <-tick:
|
||||
fmt.Println("tick.")
|
||||
case <-boom:
|
||||
fmt.Println("BOOM!")
|
||||
return
|
||||
default:
|
||||
fmt.Println(" .")
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user