From ec4adf21e0451f3fb7da33932d6cac168ddeaa93 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 8 Dec 2017 10:07:04 +0100 Subject: [PATCH] Cleanup from PR comments --- common/repeat_timer.go | 20 ++++++++++---------- common/throttle_timer.go | 4 ++-- common/throttle_timer_test.go | 3 --- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/common/repeat_timer.go b/common/repeat_timer.go index b3eb107d2..77f736034 100644 --- a/common/repeat_timer.go +++ b/common/repeat_timer.go @@ -20,7 +20,7 @@ type RepeatTimer struct { stopped bool } -type repeatCommand int32 +type repeatCommand int8 const ( Reset repeatCommand = iota @@ -67,21 +67,21 @@ func (t *RepeatTimer) run() { // stop goroutine if the input says so // don't close channels, as closed channels mess up select reads done = t.processInput(cmd) - case <-t.ticker.C: - t.trySend() + case tick := <-t.ticker.C: + t.trySend(tick) } } } // trySend performs non-blocking send on t.Ch -func (t *RepeatTimer) trySend() { +func (t *RepeatTimer) trySend(tick time.Time) { // NOTE: this was blocking in previous version (t.Ch <- t_) - // should I use that behavior unstead of unblocking as per throttle? - // probably not: https://golang.org/src/time/sleep.go#L132 - select { - case t.output <- time.Now(): - default: - } + // probably better not: https://golang.org/src/time/sleep.go#L132 + t.output <- tick + // select { + // case t.output <- tick: + // default: + // } } // all modifications of the internal state of ThrottleTimer diff --git a/common/throttle_timer.go b/common/throttle_timer.go index 0e54f1027..a5bd6ded8 100644 --- a/common/throttle_timer.go +++ b/common/throttle_timer.go @@ -22,7 +22,7 @@ type ThrottleTimer struct { stopped bool } -type throttleCommand int32 +type throttleCommand int8 const ( Set throttleCommand = iota @@ -83,7 +83,6 @@ func (t *ThrottleTimer) processInput(cmd throttleCommand) (shutdown bool) { t.timer.Reset(t.dur) } case TQuit: - t.stopped = true shutdown = true fallthrough case Unset: @@ -125,5 +124,6 @@ func (t *ThrottleTimer) Stop() bool { return false } t.input <- TQuit + t.stopped = true return true } diff --git a/common/throttle_timer_test.go b/common/throttle_timer_test.go index 2a81bb02e..94ec1b43c 100644 --- a/common/throttle_timer_test.go +++ b/common/throttle_timer_test.go @@ -95,9 +95,6 @@ func TestThrottle(test *testing.T) { stopped := t.Stop() assert.True(stopped) - time.Sleep(longwait) - assert.Equal(5, c.Count()) - // extra calls to stop don't block t.Stop() }