From 7441d92eb5b1da27a6d03b1bdc271c5bc1b529f5 Mon Sep 17 00:00:00 2001 From: Jean-Louis Huynen Date: Tue, 17 Mar 2020 11:22:34 +0100 Subject: [PATCH] chg: [signaling] merge OS signaling and error handling routines --- main.go | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index 4eda77e..b9cc682 100644 --- a/main.go +++ b/main.go @@ -58,15 +58,26 @@ var ( ) func main() { + // Create a chan to get the goroutines errors messages + pullreturn := make(chan error, 1) + // Create a chan to get os Signals sortie := make(chan os.Signal, 1) signal.Notify(sortie, os.Interrupt, os.Kill) - // Signal goroutine + // OS signaling and error handling goroutine go func() { - <-sortie - fmt.Println("Exiting.") - compilegr.Wait() - log.Println("Exit") - os.Exit(0) + select { + case <-sortie: + fmt.Println("Exiting.") + compilegr.Wait() + log.Println("Exit") + os.Exit(0) + case err := <-pullreturn: + log.Println(err) + fmt.Println("Exiting.") + compilegr.Wait() + log.Println("Exit.") + os.Exit(1) + } }() // Setting up log file @@ -154,18 +165,6 @@ func main() { redisCompilers = newPool(rp.redisHost+":"+rp.redisPort, rp.redisDBCount) redisInput = newPool(ri.redisHost+":"+ri.redisPort, 16) - // Create a chan to get the goroutines errors messages - pullreturn := make(chan error, 1) - // Launching Pull routines monitoring - go func() { - select { - case err := <-pullreturn: - log.Println(err) - os.Exit(1) - log.Println("Exit.") - } - }() - // Init compiler depending on the compiler flags: if *all { // Init all compilers