Skip to content

Instantly share code, notes, and snippets.

@aladine
Created April 8, 2018 15:13
Show Gist options
  • Save aladine/69ccfc193c29bd2cb50c72d464b30cf6 to your computer and use it in GitHub Desktop.
Save aladine/69ccfc193c29bd2cb50c72d464b30cf6 to your computer and use it in GitHub Desktop.
Golang program where time.After didn'trigger
package main
import (
"fmt"
"time"
)
func main() {
ticker := time.NewTicker(5 * time.Second)
for {
select {
case <-time.After(30 * time.Second):
// after 5 minutes, it will stop this anyway
fmt.Println("stop 5 m")
ticker.Stop()
return
case <-ticker.C:
// this will check flag every 5s
fmt.Println("stop 5s")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment