Merge branch 'master' into ethereum
This commit is contained in:
commit
394a773fc3
14
blockbook.go
14
blockbook.go
@ -254,6 +254,7 @@ func main() {
|
||||
|
||||
func tickAndDebounce(tickTime time.Duration, debounceTime time.Duration, input chan struct{}, f func()) {
|
||||
timer := time.NewTimer(tickTime)
|
||||
var firstDebounce time.Time
|
||||
Loop:
|
||||
for {
|
||||
select {
|
||||
@ -265,12 +266,21 @@ Loop:
|
||||
if !ok {
|
||||
break Loop
|
||||
}
|
||||
// debounce for debounceTime
|
||||
timer.Reset(debounceTime)
|
||||
if firstDebounce.IsZero() {
|
||||
firstDebounce = time.Now()
|
||||
}
|
||||
// debounce for up to debounceTime period
|
||||
// afterwards execute immediately
|
||||
if firstDebounce.Add(debounceTime).After(time.Now()) {
|
||||
timer.Reset(debounceTime)
|
||||
} else {
|
||||
timer.Reset(0)
|
||||
}
|
||||
case <-timer.C:
|
||||
// do the action and start the loop again
|
||||
f()
|
||||
timer.Reset(tickTime)
|
||||
firstDebounce = time.Time{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user