只执行一次

This commit is contained in:
liuxiaobo 2025-06-07 23:51:40 +08:00
parent d9484a75bc
commit 41bca1164d

View File

@ -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 {