From 80fd57a3bc86f48398680264fb8305d9f0da992a Mon Sep 17 00:00:00 2001 From: "Stephen M. McQuay" Date: Mon, 3 Sep 2012 08:39:05 -0600 Subject: [PATCH] example using a default statement in a select to sidestep blocking --- concurrency/default-select/go.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 concurrency/default-select/go.go diff --git a/concurrency/default-select/go.go b/concurrency/default-select/go.go new file mode 100644 index 0000000..72aebd3 --- /dev/null +++ b/concurrency/default-select/go.go @@ -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) + } + } +}