Skip to content

Instantly share code, notes, and snippets.

@hackerzhut
Created April 16, 2019 11:25
Show Gist options
  • Save hackerzhut/f5304fcf46f65fe4f391daf3c8e3ddd0 to your computer and use it in GitHub Desktop.
Save hackerzhut/f5304fcf46f65fe4f391daf3c8e3ddd0 to your computer and use it in GitHub Desktop.
Timer
package main
import (
"fmt"
"time"
)
// Suggestions from golang-nuts
// http://play.golang.org/p/Ctg3_AQisl
func doEvery(d time.Duration, f func(time.Time)) {
for x := range time.Tick(d) {
f(x)
}
}
func helloworld(t time.Time) {
fmt.Printf("%v: Hello, World!\n", t)
}
func main() {
doEvery(20*time.Millisecond, helloworld)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment