Created
April 16, 2019 11:25
-
-
Save hackerzhut/f5304fcf46f65fe4f391daf3c8e3ddd0 to your computer and use it in GitHub Desktop.
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
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