mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-15 06:11:20 +00:00
Cleanup from PR comments
This commit is contained in:
@ -20,7 +20,7 @@ type RepeatTimer struct {
|
|||||||
stopped bool
|
stopped bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type repeatCommand int32
|
type repeatCommand int8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Reset repeatCommand = iota
|
Reset repeatCommand = iota
|
||||||
@ -67,21 +67,21 @@ func (t *RepeatTimer) run() {
|
|||||||
// stop goroutine if the input says so
|
// stop goroutine if the input says so
|
||||||
// don't close channels, as closed channels mess up select reads
|
// don't close channels, as closed channels mess up select reads
|
||||||
done = t.processInput(cmd)
|
done = t.processInput(cmd)
|
||||||
case <-t.ticker.C:
|
case tick := <-t.ticker.C:
|
||||||
t.trySend()
|
t.trySend(tick)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// trySend performs non-blocking send on t.Ch
|
// 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_)
|
// NOTE: this was blocking in previous version (t.Ch <- t_)
|
||||||
// should I use that behavior unstead of unblocking as per throttle?
|
// probably better not: https://golang.org/src/time/sleep.go#L132
|
||||||
// probably not: https://golang.org/src/time/sleep.go#L132
|
t.output <- tick
|
||||||
select {
|
// select {
|
||||||
case t.output <- time.Now():
|
// case t.output <- tick:
|
||||||
default:
|
// default:
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
// all modifications of the internal state of ThrottleTimer
|
// all modifications of the internal state of ThrottleTimer
|
||||||
|
@ -22,7 +22,7 @@ type ThrottleTimer struct {
|
|||||||
stopped bool
|
stopped bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type throttleCommand int32
|
type throttleCommand int8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Set throttleCommand = iota
|
Set throttleCommand = iota
|
||||||
@ -83,7 +83,6 @@ func (t *ThrottleTimer) processInput(cmd throttleCommand) (shutdown bool) {
|
|||||||
t.timer.Reset(t.dur)
|
t.timer.Reset(t.dur)
|
||||||
}
|
}
|
||||||
case TQuit:
|
case TQuit:
|
||||||
t.stopped = true
|
|
||||||
shutdown = true
|
shutdown = true
|
||||||
fallthrough
|
fallthrough
|
||||||
case Unset:
|
case Unset:
|
||||||
@ -125,5 +124,6 @@ func (t *ThrottleTimer) Stop() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
t.input <- TQuit
|
t.input <- TQuit
|
||||||
|
t.stopped = true
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -95,9 +95,6 @@ func TestThrottle(test *testing.T) {
|
|||||||
|
|
||||||
stopped := t.Stop()
|
stopped := t.Stop()
|
||||||
assert.True(stopped)
|
assert.True(stopped)
|
||||||
time.Sleep(longwait)
|
|
||||||
assert.Equal(5, c.Count())
|
|
||||||
|
|
||||||
// extra calls to stop don't block
|
// extra calls to stop don't block
|
||||||
t.Stop()
|
t.Stop()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user