mirror of
https://github.com/tendermint/tendermint.git
synced 2026-06-03 12:56:22 +00:00
Made throttle output non-blocking
This commit is contained in:
@@ -30,7 +30,7 @@ const (
|
||||
)
|
||||
|
||||
func NewThrottleTimer(name string, dur time.Duration) *ThrottleTimer {
|
||||
c := make(chan struct{}, 1)
|
||||
c := make(chan struct{})
|
||||
var t = &ThrottleTimer{
|
||||
Name: name,
|
||||
Ch: c,
|
||||
@@ -54,12 +54,22 @@ func (t *ThrottleTimer) run() {
|
||||
return
|
||||
}
|
||||
case <-t.timer.C:
|
||||
t.isSet = false
|
||||
t.output <- struct{}{}
|
||||
t.trySend()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// trySend performs non-blocking send on t.output (t.Ch)
|
||||
func (t *ThrottleTimer) trySend() {
|
||||
select {
|
||||
case t.output <- struct{}{}:
|
||||
t.isSet = false
|
||||
default:
|
||||
// if we just want to drop, replace this with t.isSet = false
|
||||
t.timer.Reset(t.dur)
|
||||
}
|
||||
}
|
||||
|
||||
// all modifications of the internal state of ThrottleTimer
|
||||
// happen in this method. It is only called from the run goroutine
|
||||
// so we avoid any race conditions
|
||||
|
||||
Reference in New Issue
Block a user