From 0368b6d0f7069be078ca6dba2c8bb3ed06d9f03a Mon Sep 17 00:00:00 2001 From: xengineering Date: Tue, 7 May 2024 21:43:28 +0200 Subject: Introduce await() function This improves readability of the main() function. --- main.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 6da8e93..84a0761 100644 --- a/main.go +++ b/main.go @@ -42,9 +42,14 @@ func main() { go server.Start() defer server.Stop() + await(syscall.SIGTERM, syscall.SIGINT) +} + +func await(signals ...syscall.Signal) { listener := make(chan os.Signal) - signal.Notify(listener, syscall.SIGTERM) - signal.Notify(listener, syscall.SIGINT) + for _, s := range signals { + signal.Notify(listener, s) + } sig := <-listener - log.Printf("Cleaning up due to OS signal '%v'\n", sig) + log.Printf("Received OS signal '%v'\n", sig) } -- cgit v1.2.3-70-g09d2