Created
July 21, 2018 23:16
-
-
Save vdparikh/0a56dc704dc59bb838fbdeaf64c88a78 to your computer and use it in GitHub Desktop.
Execute a function at duration
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 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