mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-19 14:34:17 +00:00
proper string formatting for txs
This commit is contained in:
@@ -7,16 +7,17 @@ RepeatTimer repeatedly sends a struct{}{} to .Ch after each "dur" period.
|
||||
It's good for keeping connections alive.
|
||||
*/
|
||||
type RepeatTimer struct {
|
||||
Name string
|
||||
Ch chan struct{}
|
||||
quit chan struct{}
|
||||
dur time.Duration
|
||||
timer *time.Timer
|
||||
}
|
||||
|
||||
func NewRepeatTimer(dur time.Duration) *RepeatTimer {
|
||||
func NewRepeatTimer(name string, dur time.Duration) *RepeatTimer {
|
||||
var ch = make(chan struct{})
|
||||
var quit = make(chan struct{})
|
||||
var t = &RepeatTimer{Ch: ch, dur: dur, quit: quit}
|
||||
var t = &RepeatTimer{Name: name, Ch: ch, dur: dur, quit: quit}
|
||||
t.timer = time.AfterFunc(dur, t.fireRoutine)
|
||||
return t
|
||||
}
|
||||
@@ -26,6 +27,9 @@ func (t *RepeatTimer) fireRoutine() {
|
||||
case t.Ch <- struct{}{}:
|
||||
t.timer.Reset(t.dur)
|
||||
case <-t.quit:
|
||||
// do nothing
|
||||
default:
|
||||
t.timer.Reset(t.dur)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ If a long continuous burst of .Set() calls happens, ThrottleTimer fires
|
||||
at most once every "dur".
|
||||
*/
|
||||
type ThrottleTimer struct {
|
||||
Name string
|
||||
Ch chan struct{}
|
||||
quit chan struct{}
|
||||
dur time.Duration
|
||||
@@ -19,10 +20,10 @@ type ThrottleTimer struct {
|
||||
isSet uint32
|
||||
}
|
||||
|
||||
func NewThrottleTimer(dur time.Duration) *ThrottleTimer {
|
||||
func NewThrottleTimer(name string, dur time.Duration) *ThrottleTimer {
|
||||
var ch = make(chan struct{})
|
||||
var quit = make(chan struct{})
|
||||
var t = &ThrottleTimer{Ch: ch, dur: dur, quit: quit}
|
||||
var t = &ThrottleTimer{Name: name, Ch: ch, dur: dur, quit: quit}
|
||||
t.timer = time.AfterFunc(dur, t.fireRoutine)
|
||||
t.timer.Stop()
|
||||
return t
|
||||
@@ -33,6 +34,9 @@ func (t *ThrottleTimer) fireRoutine() {
|
||||
case t.Ch <- struct{}{}:
|
||||
atomic.StoreUint32(&t.isSet, 0)
|
||||
case <-t.quit:
|
||||
// do nothing
|
||||
default:
|
||||
t.timer.Reset(t.dur)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user