Start 非阻塞的方式启动timerSchedule
()
| 98 | |
| 99 | // Start 非阻塞的方式启动timerSchedule |
| 100 | func (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 时间轮定时器 自动调度 |
| 120 | func NewAutoExecTimerScheduler() *TimerScheduler { |