This commit is contained in:
Jae Kwon
2014-06-17 01:28:43 -07:00
parent 6f6582100d
commit 4e09037e9f
5 changed files with 43 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
package blocks
import (
. "github.com/tendermint/tendermint/common"
. "github.com/tendermint/tendermint/binary"
"io"
)

View File

@@ -1,6 +1,7 @@
package blocks
import (
. "github.com/tendermint/tendermint/common"
. "github.com/tendermint/tendermint/binary"
"io"
)

View File

@@ -1,6 +1,7 @@
package blocks
import (
. "github.com/tendermint/tendermint/common"
. "github.com/tendermint/tendermint/binary"
"io"
)

39
common/debounce.go Normal file
View 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()
}

View File

@@ -1,4 +1,4 @@
package blocks
package common
import (
"fmt"