Skip to content

Instantly share code, notes, and snippets.

@wjx0912
Created April 11, 2018 13:35
Show Gist options
  • Save wjx0912/1acc11779ac9e19727e420a424c06398 to your computer and use it in GitHub Desktop.
Save wjx0912/1acc11779ac9e19727e420a424c06398 to your computer and use it in GitHub Desktop.
golang: three way use timer
// (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