MCPcopy
hub / github.com/aceld/zinx / Start

Method Start

ztimer/timerscheduler.go:100–117  ·  view source on GitHub ↗

Start 非阻塞的方式启动timerSchedule

()

Source from the content-addressed store, hash-verified

98
99// Start 非阻塞的方式启动timerSchedule
100func (ts *TimerScheduler) Start() {
101 go func() {
102 for {
103 //当前时间
104 now := UnixMilli()
105 //获取最近MaxTimeDelay 毫秒的超时定时器集合
106 timerList := ts.tw.GetTimerWithIn(MaxTimeDelay * time.Millisecond)
107 for _, timer := range timerList {
108 if math.Abs(float64(now-timer.unixts)) > MaxTimeDelay {
109 //已经超时的定时器,报警
110 zlog.Error("want call at ", timer.unixts, "; real call at", now, "; delay ", now-timer.unixts)
111 }
112 ts.triggerChan <- timer.delayFunc
113 }
114 time.Sleep(MaxTimeDelay / 2 * time.Millisecond)
115 }
116 }()
117}
118
119// NewAutoExecTimerScheduler 时间轮定时器 自动调度
120func NewAutoExecTimerScheduler() *TimerScheduler {

Callers 2

TestNewTimerSchedulerFunction · 0.95

Calls 3

ErrorFunction · 0.92
UnixMilliFunction · 0.85
GetTimerWithInMethod · 0.80

Tested by 1

TestNewTimerSchedulerFunction · 0.76