Reputation: 2877
Are there any alternatives to Golang's time
package? I can't come to grips with its clunky interface and strange way of doing things. The language overall is great, but this part of it just never clicked with me.
Anyone? A really good, thorough tutorial would work too (I have not managed to find one yet)
What I'm trying to do right now is a goroutine
that updates only 10 times per second (or any variable interval that I set it to). I've not yet implemented it, as the package is not playing nice. Here's the psuedo code.
function GoRoutine(updatesPerSecond int) {
interval = 1000msec / updatesPerSecond
for {
if enoughTimeHasPassed {
doThings()
}
}
}
Upvotes: 2
Views: 1108
Reputation: 99274
Did you read the documentation at http://golang.org/pkg/time/?
You need to use a Ticker:
func Loop(fps int) {
t := time.NewTicker(time.Second / time.Duration(fps))
for t := range t.C {
fmt.Println("tick", t)
}
}
func main() {
go Loop(60)
time.Sleep(10 * time.Second)
}
then use it like go Loop(60)
.
Upvotes: 7