Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func main(){
- go WaitForInterrupt(func() { worker.Stop() })
- work.Run()
- }
- func WaitForInterrupt(f func()) {
- // Set up channel on which to send signal notifications.
- // We must use a buffered channel or risk missing the signal
- // if we're not ready to receive when the signal is sent.
- c := make(chan os.Signal, 1)
- signal.Notify(c, syscall.SIGTERM, os.Interrupt, os.Kill) //调用系统函数
- // Block until a signal is received.
- s := <-c
- log.Println("Receiving signal:", s)
- f()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement