internal helper, should call with lock held
(evtType TimerEventType, blockNum uint32)
| 191 | // internal helper, should call with lock held |
| 192 | // |
| 193 | func (self *EventTimer) startEventTimer(evtType TimerEventType, blockNum uint32) error { |
| 194 | timers := self.eventTimers[evtType] |
| 195 | if t, present := timers[blockNum]; present { |
| 196 | t.Stop() |
| 197 | delete(timers, blockNum) |
| 198 | log.Infof("timer (type: %d) for %d got reset", evtType, blockNum) |
| 199 | } |
| 200 | |
| 201 | timeout := self.getEventTimeout(evtType) |
| 202 | if timeout == 0 { |
| 203 | log.Errorf("invalid timeout for event %d, blkNum %d", evtType, blockNum) |
| 204 | return fmt.Errorf("invalid timeout for event %d, blkNum %d", evtType, blockNum) |
| 205 | } |
| 206 | timers[blockNum] = time.AfterFunc(timeout, func() { |
| 207 | self.C <- &TimerEvent{ |
| 208 | evtType: evtType, |
| 209 | blockNum: blockNum, |
| 210 | } |
| 211 | }) |
| 212 | return nil |
| 213 | } |
| 214 | |
| 215 | // |
| 216 | // internal helper, should call with lock held |