Created
January 14, 2021 09:08
-
-
Save farkroft/5437601aa643c0ab1059eacc4f53a852 to your computer and use it in GitHub Desktop.
Golang Time Ticker Every 1ms
This file contains 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 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