From a0f54cbe5ac2cd8b8296c2c57c30029dd349cff0 Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Sun, 4 Feb 2018 16:08:26 +0100 Subject: Align with go library layout --- src/timer.go | 59 ----------------------------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 src/timer.go (limited to 'src/timer.go') diff --git a/src/timer.go b/src/timer.go deleted file mode 100644 index f00ca49..0000000 --- a/src/timer.go +++ /dev/null @@ -1,59 +0,0 @@ -package main - -import ( - "time" -) - -type Timer struct { - pending AtomicBool - timer *time.Timer -} - -/* Starts the timer if not already pending - */ -func (t *Timer) Start(dur time.Duration) bool { - set := t.pending.Swap(true) - if !set { - t.timer.Reset(dur) - return true - } - return false -} - -/* Stops the timer - */ -func (t *Timer) Stop() { - set := t.pending.Swap(true) - if set { - t.timer.Stop() - select { - case <-t.timer.C: - default: - } - } - t.pending.Set(false) -} - -func (t *Timer) Pending() bool { - return t.pending.Get() -} - -func (t *Timer) Reset(dur time.Duration) { - t.pending.Set(false) - t.Start(dur) -} - -func (t *Timer) Wait() <-chan time.Time { - return t.timer.C -} - -func NewTimer() (t Timer) { - t.pending.Set(false) - t.timer = time.NewTimer(0) - t.timer.Stop() - select { - case <-t.timer.C: - default: - } - return -} -- cgit v1.2.3