| 123 | } |
| 124 | |
| 125 | func (self *EventTimer) StartTimer(Idx uint32, timeout time.Duration) { |
| 126 | self.lock.Lock() |
| 127 | defer self.lock.Unlock() |
| 128 | |
| 129 | if t, present := self.normalTimers[Idx]; present { |
| 130 | t.Stop() |
| 131 | log.Infof("timer for %d got reset", Idx) |
| 132 | } |
| 133 | |
| 134 | self.normalTimers[Idx] = time.AfterFunc(timeout, func() { |
| 135 | // remove timer from map |
| 136 | self.lock.Lock() |
| 137 | defer self.lock.Unlock() |
| 138 | delete(self.normalTimers, Idx) |
| 139 | |
| 140 | self.C <- &TimerEvent{ |
| 141 | evtType: EventMax, |
| 142 | blockNum: Idx, |
| 143 | } |
| 144 | }) |
| 145 | } |
| 146 | |
| 147 | func (self *EventTimer) CancelTimer(idx uint32) { |
| 148 | self.lock.Lock() |