broadcast/cmd/echo/main.go

26 lines
346 B
Go
Raw Normal View History

2023-02-13 23:49:45 +01:00
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")
}
}
}