github.com/mattevans/edward@v1.9.2/edward/testdata/features/edward-test-noport/main.go (about) 1 // A simple executable that stays runnning until an interrupt is received 2 // Based on: https://gobyexample.com/signals 3 package main 4 5 import ( 6 "fmt" 7 "os" 8 "os/signal" 9 "time" 10 ) 11 12 func main() { 13 timer := time.NewTimer(5 * time.Second) 14 defer timer.Stop() 15 16 stop := make(chan os.Signal, 1) 17 signal.Notify(stop, os.Interrupt) 18 19 fmt.Println("Started") 20 21 select { 22 case <-stop: 23 fmt.Println("Terminated") 24 case <-timer.C: 25 fmt.Println("Timed out") 26 } 27 28 fmt.Println("Exiting") 29 }