Let's take this example from the GoTour, as it illustrates my problem with processing SDL events only when there are events.
package main
import (
"fmt"
"time"
)
func main() {
tick := time.Tick(1e8)
boom := time.After(5e8)
for {
select {
case <-tick:
fmt.Println("tick.")
case <-boom:
fmt.Println("BOOM!")
return
default:
fmt.Println(" .")
time.Sleep(5e7)
}
}
}
This works. But what if I don't want to print or sleep in the default case, but just want to keep looping? I tried this:
case <-boom:
fmt.Println("BOOM!")
return
default: // Nothing here.
}
}
}
but it blocks.
I have seen here and there a sentence about goroutines scheduling, but I didn't understand them. So I guess I have two questions:
1) Why does it block?
2) How do I make it do nothing without blocking?