mirror of
https://github.com/tendermint/tendermint.git
synced 2026-04-15 13:17:01 +00:00
.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package blocks
|
||||
|
||||
import (
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
. "github.com/tendermint/tendermint/binary"
|
||||
"io"
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package blocks
|
||||
|
||||
import (
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
. "github.com/tendermint/tendermint/binary"
|
||||
"io"
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package blocks
|
||||
|
||||
import (
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
. "github.com/tendermint/tendermint/binary"
|
||||
"io"
|
||||
)
|
||||
|
||||
39
common/debounce.go
Normal file
39
common/debounce.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
/* Debouncer */
|
||||
type Debouncer struct {
|
||||
Ch chan struct{}
|
||||
quit chan struct{}
|
||||
dur time.Duration
|
||||
timer *time.Timer
|
||||
}
|
||||
|
||||
func NewDebouncer(dur time.Duration) *Debouncer {
|
||||
var timer *time.Timer
|
||||
var ch = make(chan struct{})
|
||||
var quit = make(chan struct{})
|
||||
fire := func() {
|
||||
go func() {
|
||||
select {
|
||||
case ch <- struct{}{}:
|
||||
case <-quit:
|
||||
}
|
||||
}()
|
||||
timer.Reset(dur)
|
||||
}
|
||||
timer = time.AfterFunc(dur, fire)
|
||||
return &Debouncer{Ch:ch, dur:dur, quit:quit, timer:timer}
|
||||
}
|
||||
|
||||
func (d *Debouncer) Reset() {
|
||||
d.timer.Reset(d.dur)
|
||||
}
|
||||
|
||||
func (d *Debouncer) Stop() bool {
|
||||
close(d.quit)
|
||||
return d.timer.Stop()
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package blocks
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
Reference in New Issue
Block a user