Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. func main(){
  2. go WaitForInterrupt(func() { worker.Stop() })
  3.  
  4. work.Run()
  5. }
  6.  
  7. func WaitForInterrupt(f func()) {
  8.  
  9. // Set up channel on which to send signal notifications.
  10. // We must use a buffered channel or risk missing the signal
  11. // if we're not ready to receive when the signal is sent.
  12. c := make(chan os.Signal, 1)
  13. signal.Notify(c, syscall.SIGTERM, os.Interrupt, os.Kill) //调用系统函数
  14.  
  15. // Block until a signal is received.
  16. s := <-c
  17.  
  18. log.Println("Receiving signal:", s)
  19.  
  20. f()
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement