diff --git a/service/baseService.go b/service/baseService.go index 188e917..c5841b6 100644 --- a/service/baseService.go +++ b/service/baseService.go @@ -8,6 +8,7 @@ import ( "github.com/fox/fox/log" "github.com/fox/fox/safeChan" "github.com/fox/fox/timer" + "sync" "time" ) @@ -15,6 +16,7 @@ type BaseService struct { *timer.Timer type_ string name string + once sync.Once onFunc IOnFunc sender ISender @@ -174,7 +176,9 @@ func (s *BaseService) run() { } func (s *BaseService) Run() { - ksync.GoSafe(s.run, s.Run) + s.once.Do(func() { + ksync.GoSafe(s.run, s.run) + }) } func (s *BaseService) Log(format string, a ...any) string {