broadcast/cmd/echo/main.go

26 lines
346 B
Go

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")
}
}
}