Is it possible to use Ticker to implemented the graceful termination of a long running daemon process? I read the other related thread on here that you should always close the channel to avoid memory leak, but if I run this in a daemon mode (let said I use daemonize to handle the daemon operation outside of golang), and there's really no way for it to do any collective cleanup before the process is terminated. Unless I'm missing something, I'm here to ask whether there's an alternative/better to do this in Golang
func main() {
ticker := time.NewTicker(Interval)
workers := make(chan bool, 1)
for t := range ticker.C {
select {
case <- ticker.C:
log.Println("Scheduled task is triggered.", t)
go runWorker(workers)
case <- workers:
log.Println("Scheduled task is completed.")
// can't return, it needs to be continue running
}
}
}