Created
April 11, 2018 13:35
-
-
Save wjx0912/1acc11779ac9e19727e420a424c06398 to your computer and use it in GitHub Desktop.
golang: three way use timer
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
// (A) | |
time.AfterFunc(5 * time.Minute, func() { | |
fmt.Printf("expired") | |
} | |
// (B) create a Timer object | |
timer := time.NewTimer(5 * time.Minute) | |
<-timer.C | |
fmt.Printf("expired") | |
// (C) time.After() returns timer.C internally | |
<-time.After(5 * time.Minute) | |
fmt.Printf("expired") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment