mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-15 08:01:19 +00:00
First pass of PR updates
This commit is contained in:
parent
4ec7883891
commit
0a8721113a
@ -11,10 +11,11 @@ If a long continuous burst of .Set() calls happens, ThrottleTimer fires
|
|||||||
at most once every "dur".
|
at most once every "dur".
|
||||||
*/
|
*/
|
||||||
type ThrottleTimer struct {
|
type ThrottleTimer struct {
|
||||||
Name string
|
Name string
|
||||||
Ch chan struct{}
|
Ch <-chan struct{}
|
||||||
input chan command
|
output chan<- struct{}
|
||||||
dur time.Duration
|
input chan command
|
||||||
|
dur time.Duration
|
||||||
|
|
||||||
timer *time.Timer
|
timer *time.Timer
|
||||||
isSet bool
|
isSet bool
|
||||||
@ -29,12 +30,14 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewThrottleTimer(name string, dur time.Duration) *ThrottleTimer {
|
func NewThrottleTimer(name string, dur time.Duration) *ThrottleTimer {
|
||||||
|
c := make(chan struct{}, 1)
|
||||||
var t = &ThrottleTimer{
|
var t = &ThrottleTimer{
|
||||||
Name: name,
|
Name: name,
|
||||||
Ch: make(chan struct{}, 1),
|
Ch: c,
|
||||||
dur: dur,
|
dur: dur,
|
||||||
input: make(chan command),
|
output: c,
|
||||||
timer: time.NewTimer(dur),
|
input: make(chan command),
|
||||||
|
timer: time.NewTimer(dur),
|
||||||
}
|
}
|
||||||
t.timer.Stop()
|
t.timer.Stop()
|
||||||
go t.run()
|
go t.run()
|
||||||
@ -47,14 +50,12 @@ func (t *ThrottleTimer) run() {
|
|||||||
case cmd := <-t.input:
|
case cmd := <-t.input:
|
||||||
// stop goroutine if the input says so
|
// stop goroutine if the input says so
|
||||||
if t.processInput(cmd) {
|
if t.processInput(cmd) {
|
||||||
// TODO: do we want to close the channels???
|
close(t.output)
|
||||||
// close(t.Ch)
|
|
||||||
// close(t.input)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case <-t.timer.C:
|
case <-t.timer.C:
|
||||||
t.isSet = false
|
t.isSet = false
|
||||||
t.Ch <- struct{}{}
|
t.output <- struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,7 +81,6 @@ func (t *ThrottleTimer) processInput(cmd command) (shutdown bool) {
|
|||||||
default:
|
default:
|
||||||
panic("unknown command!")
|
panic("unknown command!")
|
||||||
}
|
}
|
||||||
// return true
|
|
||||||
return shutdown
|
return shutdown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type thCounter struct {
|
type thCounter struct {
|
||||||
input chan struct{}
|
input <-chan struct{}
|
||||||
mtx sync.Mutex
|
mtx sync.Mutex
|
||||||
count int
|
count int
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user