I have to execute some statements say every minute. I am not sure which one of the following I should follow. It would be great if someone can explain the pros and cons in terms of memory and CPU.
time.Sleep()
func main() {
go func() {
for {
time.Sleep(time.Minute)
fmt.Println("Hi")
}
}()
time.Sleep(10 * time.Minute) //just to keep main thread running
}
Or Ticker
func main() {
go func() {
for _ = range time.Tick(time.Minute) {
fmt.Println("Hi")
}
}()
time.Sleep(10 * time.Minute) //just to keep main thread running
}