This commit is contained in:
xxjwxc
2020-05-26 02:04:46 +08:00
parent 0ac9cdd0af
commit eb574b852a
7 changed files with 194 additions and 18 deletions

32
mysignal/mysignal.go Normal file
View File

@@ -0,0 +1,32 @@
package mysignal
import (
"os"
"os/signal"
"syscall"
)
type notify struct {
cc chan os.Signal
}
// New new signal
func New() *notify {
return &notify{
cc: make(chan os.Signal, 1),
}
}
func (s *notify) Wait() {
signal.Notify(s.cc, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
select {
// wait on kill signal
case <-s.cc:
}
}
// NotifyStop 发送停止信号
func (s *notify) NotifyStop() {
s.cc <- syscall.SIGINT
}