ProcessTimers should be called periodically to process the timers
()
| 73 | |
| 74 | // ProcessTimers should be called periodically to process the timers |
| 75 | func (tm *TimerManager) ProcessTimers() { |
| 76 | |
| 77 | now := time.Now() |
| 78 | for pos, t := range tm.timers { |
| 79 | // If empty entry, ignore |
| 80 | if t.id == 0 { |
| 81 | continue |
| 82 | } |
| 83 | // Checks if entry expired |
| 84 | if now.After(t.expire) { |
| 85 | if t.period == 0 { |
| 86 | tm.timers[pos] = timeout{} |
| 87 | } else { |
| 88 | tm.timers[pos].expire = now.Add(t.period) |
| 89 | } |
| 90 | t.cb(t.arg) |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // setTimer sets a new timer with the specified duration |
| 96 | func (tm *TimerManager) setTimer(td time.Duration, periodic bool, arg interface{}, cb TimerCallback) int { |