Files
public/mysignal/mysignal.go
xxjwxc eb574b852a new
2020-05-26 02:04:46 +08:00

33 lines
439 B
Go

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
}