mirror of
https://github.com/xxjwxc/public.git
synced 2025-09-26 20:01:19 +08:00
new
This commit is contained in:
32
mysignal/mysignal.go
Normal file
32
mysignal/mysignal.go
Normal 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 ¬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
|
||||
}
|
Reference in New Issue
Block a user