package main import ( "context" "fmt" "os" "os/signal" "time" ) func main() { ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel() ticker := time.NewTicker(time.Second) for { select { case <-ctx.Done(): fmt.Println("Bye...") return case <-ticker.C: fmt.Println("Still alive") } } }