From c713ba7a332a6ea63d3b51421f04b8d9f9435ac3 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Sat, 6 May 2023 23:29:54 +0800 Subject: [PATCH] chore: refactor (#39) * feat: support connection stats * chore: refactor --- stat.go | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/stat.go b/stat.go index 8554ec5..635c5dd 100644 --- a/stat.go +++ b/stat.go @@ -31,21 +31,18 @@ func NewStater(staters ...Stater) Stater { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM) - for { - select { - case sig := <-c: - signal.Stop(c) - stat.Stop() - - p, err := os.FindProcess(syscall.Getpid()) - if err != nil { - fmt.Println(err) - os.Exit(0) - } - - if err := p.Signal(sig); err != nil { - fmt.Println(err) - } + for sig := range c { + signal.Stop(c) + stat.Stop() + + p, err := os.FindProcess(syscall.Getpid()) + if err != nil { + fmt.Println(err) + os.Exit(0) + } + + if err := p.Signal(sig); err != nil { + fmt.Println(err) } } }()