StopAndDrainTimer stops the timer and drains its channel if a tick was already queued.
(timer *time.Timer)
| 4 | |
| 5 | // StopAndDrainTimer stops the timer and drains its channel if a tick was already queued. |
| 6 | func StopAndDrainTimer(timer *time.Timer) { |
| 7 | if timer == nil { |
| 8 | return |
| 9 | } |
| 10 | |
| 11 | if !timer.Stop() { |
| 12 | select { |
| 13 | case <-timer.C: |
| 14 | default: |
| 15 | } |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | // ResetTimer safely resets timer, handling the required stop+drain sequence first. |
| 20 | func ResetTimer(timer *time.Timer, d time.Duration) { |