Skip to content

Instantly share code, notes, and snippets.

@farkroft
Created January 14, 2021 09:08
Show Gist options
  • Save farkroft/5437601aa643c0ab1059eacc4f53a852 to your computer and use it in GitHub Desktop.
Save farkroft/5437601aa643c0ab1059eacc4f53a852 to your computer and use it in GitHub Desktop.
Golang Time Ticker Every 1ms
package main
import (
"fmt"
"time"
)
func main() {
done := make(chan bool)
i := 0
ticker := time.NewTicker(1 * time.Millisecond)
go func() {
for {
select {
case <-done:
ticker.Stop()
case t := <-ticker.C:
if i > 10 {
done <- true
}
i++
fmt.Println(t.Nanosecond() / 1000000)
}
}
}()
for {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment