Skip to content

Instantly share code, notes, and snippets.

@Imater
Created August 25, 2014 15:25
Show Gist options
  • Save Imater/8c882bb6327852162a6a to your computer and use it in GitHub Desktop.
Save Imater/8c882bb6327852162a6a to your computer and use it in GitHub Desktop.
timer with select case
package main
import "time"
import "fmt"
func main() {
doneChan := make(chan bool)
go func() {
time.Sleep(time.Second * 20)
doneChan <- true
}()
for {
select {
case <- time.NewTimer(time.Second*10).C:
fmt.Println("Timer expired")
case <- time.NewTicker(time.Millisecond * 400).C:
fmt.Println("Ticker ticked")
case <- doneChan:
fmt.Println("Done")
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment