mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-04 15:17:02 +00:00
created "Node"
This commit is contained in:
@@ -2,7 +2,10 @@ package common
|
||||
|
||||
import "time"
|
||||
|
||||
/* RepeatTimer */
|
||||
/*
|
||||
RepeatTimer repeatedly sends a struct{}{} to .Ch after each "dur" period.
|
||||
It's good for keeping connections alive.
|
||||
*/
|
||||
type RepeatTimer struct {
|
||||
Ch chan struct{}
|
||||
quit chan struct{}
|
||||
@@ -26,6 +29,7 @@ func (t *RepeatTimer) fireHandler() {
|
||||
}
|
||||
}
|
||||
|
||||
// Wait the duration again before firing.
|
||||
func (t *RepeatTimer) Reset() {
|
||||
t.timer.Reset(t.dur)
|
||||
}
|
||||
|
||||
+5
-1
@@ -5,7 +5,10 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
/* Throttler */
|
||||
/*
|
||||
Throttler sends a struct{}{} to .Ch "dur" after the last .Set().
|
||||
It's good for ensuring that something happens last after a burst of events.
|
||||
*/
|
||||
type Throttler struct {
|
||||
Ch chan struct{}
|
||||
quit chan struct{}
|
||||
@@ -19,6 +22,7 @@ func NewThrottler(dur time.Duration) *Throttler {
|
||||
var quit = make(chan struct{})
|
||||
var t = &Throttler{Ch: ch, dur: dur, quit: quit}
|
||||
t.timer = time.AfterFunc(dur, t.fireHandler)
|
||||
t.timer.Stop()
|
||||
return t
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user