Skip to content

Commit

Permalink
refactor(signal): Refactor async feature (#83)
Browse files Browse the repository at this point in the history
Signed-off-by: Flc゛ <[email protected]>
  • Loading branch information
flc1125 authored Jan 30, 2024
1 parent 2ff07fd commit 7486cc3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
3 changes: 2 additions & 1 deletion signal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/go-kratos/kratos/v2"

"github.com/go-kratos-ecosystem/components/v2/feature"
"github.com/go-kratos-ecosystem/components/v2/signal"
)

Expand Down Expand Up @@ -45,7 +46,7 @@ func (h *exampleHandler) Handle(sig os.Signal) {
}

type example2Handler struct{
signal.AsyncFeature // async feature
feature.AsyncFeature // async feature
}

func (h *example2Handler) Listen() []os.Signal {
Expand Down
10 changes: 0 additions & 10 deletions signal/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,3 @@ type Handler interface {
Listen() []os.Signal
Handle(os.Signal)
}

type asyncFeature interface {
Async() bool
}

type AsyncFeature struct{}

func (*AsyncFeature) Async() bool {
return true
}
4 changes: 3 additions & 1 deletion signal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os/signal"

"github.com/go-kratos/kratos/v2/log"

"github.com/go-kratos-ecosystem/components/v2/feature"
)

var DefaultRecovery = func(err interface{}, sig os.Signal, handler Handler) {
Expand Down Expand Up @@ -80,7 +82,7 @@ func (s *Server) Start(ctx context.Context) error {
if hs, ok := handlers[sig]; ok {
for _, h := range hs {
// if Support asyncFeature
if async, ok := h.(asyncFeature); ok && async.Async() {
if async, ok := h.(feature.Asyncable); ok && async.Async() {
go s.handle(sig, h)
} else {
s.handle(sig, h)
Expand Down

0 comments on commit 7486cc3

Please sign in to comment.