Skip to content

Instantly share code, notes, and snippets.

@vdparikh
Created July 21, 2018 23:16
Show Gist options
  • Save vdparikh/0a56dc704dc59bb838fbdeaf64c88a78 to your computer and use it in GitHub Desktop.
Save vdparikh/0a56dc704dc59bb838fbdeaf64c88a78 to your computer and use it in GitHub Desktop.
Execute a function at duration
package main
import (
"fmt"
"time"
)
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(2*time.Second, helloworld)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment