github.com/xmidt-org/webpa-common@v1.11.9/server/signalWait.go (about) 1 package server 2 3 import ( 4 "os" 5 6 "github.com/go-kit/kit/log" 7 "github.com/xmidt-org/webpa-common/logging" 8 ) 9 10 // SignalWait blocks until any of a set of signals is encountered. The signal which caused this function 11 // to exit is returned. A nil return indicates that the signals channel was closed. 12 // 13 // If no waitOn signals are supplied, this function will never return until the signals channel is closed. 14 // 15 // In all cases, the supplied logger is used to log information about signals that are ignored. 16 func SignalWait(logger log.Logger, signals <-chan os.Signal, waitOn ...os.Signal) os.Signal { 17 filter := make(map[os.Signal]bool) 18 for _, s := range waitOn { 19 filter[s] = true 20 } 21 22 for s := range signals { 23 if filter[s] { 24 return s 25 } 26 27 logger.Log(logging.MessageKey(), "ignoring signal", "signal", s.String()) 28 } 29 30 return nil 31 }