diff options
Diffstat (limited to 'src/misc.go')
-rw-r--r-- | src/misc.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/misc.go b/src/misc.go index 2bcb148..dd4fa63 100644 --- a/src/misc.go +++ b/src/misc.go @@ -1,5 +1,9 @@ package main +import ( + "time" +) + func min(a uint, b uint) uint { if a > b { return b @@ -13,3 +17,18 @@ func sendSignal(c chan struct{}) { default: } } + +func stopTimer(timer *time.Timer) { + if !timer.Stop() { + select { + case <-timer.C: + default: + } + } +} + +func stoppedTimer() *time.Timer { + timer := time.NewTimer(time.Hour) + stopTimer(timer) + return timer +} |