Good morning, I hope you can support me. I'm doing a dummy to test the tickers in go:
package main
import(
"fmt"
"time"
)
func main(){
ticker := time.NewTicker(time.Millisecond * 500)
go func() {
for t := range ticker.C {
fmt.Println("Tic a las", t)
}
}()
time.Sleep(time.Millisecond * 1500)
ticker.Stop()
fmt.Println("Ticker detenido:", time.Now())
var input string
fmt.Scanln(&input)
fmt.Println("done")
}
In theory, the ticker runs every 500 milliseconds and I stop it after 1500 milliseconds, so 3 ticker impressions should appear (in theory). However I got the following output:
Tic a las 2016-04-13 09:56:11.8632579 -0500 CDT
Tic a las 2016-04-13 09:56:12.363399 -0500 CDT
Ticker detenido: 2016-04-13 09:56:12.8634635 -0500 CDT
So, add the last 3 lines of the code to finish the program when you press a key, and trying again I found this:
Tic a las 2016-04-13 10:08:15.4709006 -0500 CDT
Tic a las 2016-04-13 10:08:15.9713121 -0500 CDT
Ticker detenido: 2016-04-13 10:08:16.4714132 -0500 CDT
Tic a las 2016-04-13 10:08:16.4714132 -0500 CDT
As you can see, the last two lines print 2016-04-13 10:08:16. 4714132 , it's the same date, even in milliseconds, but the main and I print first I need the print of the ticker printed first. Is there any way to correct this? Any way to give priority to the ticker thread over the main one? I hope you can support me Thanks and regards