mirror of
https://github.com/xxjwxc/public.git
synced 2025-09-26 20:01:19 +08:00
33 lines
439 B
Go
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 ¬ify{
|
|
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
|
|
}
|