go func() {
for true {
fmt.Println("Hello !!")
time.Sleep(1 * time.Second)
}
}()
ticker := time.NewTicker(1 * time.Second)
go func() {
for range ticker.C {
fmt.Println("Hello !!")
}
}()
// wAIt for 10 seconds
time.Sleep(10 *time.Second)
ticker.Stop()
done := make(chan bool)
ticker := time.NewTicker(1 * time.Second)
go func() {
for {
select {
case <-done:
ticker.Stop()
return
case <-ticker.C:
fmt.Println("Hello !!")
}
}
}()
// wait for 10 seconds
time.Sleep(10 *time.Second)
done <- true
https://stackoverflow.com/questions/53057237/how-to-schedule-a-task-at-go-periodically