Created
April 8, 2018 15:13
-
-
Save aladine/69ccfc193c29bd2cb50c72d464b30cf6 to your computer and use it in GitHub Desktop.
Golang program where time.After didn'trigger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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