diff --git a/signal/README.md b/signal/README.md index 74d2906d..ccf99804 100644 --- a/signal/README.md +++ b/signal/README.md @@ -44,7 +44,9 @@ func (h *exampleHandler) Handle(sig os.Signal) { println("exampleHandler signal:", sig) } -type example2Handler struct{} +type example2Handler struct{ + signal.AsyncFeature // async feature +} func (h *example2Handler) Listen() []os.Signal { return []os.Signal{syscall.SIGUSR1} diff --git a/signal/handler.go b/signal/handler.go index 5195d4a3..dd8ae6d1 100644 --- a/signal/handler.go +++ b/signal/handler.go @@ -9,6 +9,12 @@ type Handler interface { Handle(os.Signal) } -type AsyncFeature interface { +type asyncFeature interface { Async() bool } + +type AsyncFeature struct{} + +func (*AsyncFeature) Async() bool { + return true +} diff --git a/signal/server.go b/signal/server.go index 5389f1a6..53370400 100644 --- a/signal/server.go +++ b/signal/server.go @@ -79,8 +79,8 @@ func (s *Server) Start(ctx context.Context) error { case sig := <-ch: if hs, ok := handlers[sig]; ok { for _, h := range hs { - // if Support AsyncFeature - if async, ok := h.(AsyncFeature); ok && async.Async() { + // if Support asyncFeature + if async, ok := h.(asyncFeature); ok && async.Async() { go s.handle(sig, h) } else { s.handle(sig, h)