Add replace debounce with throttle

Update dependencies
This commit is contained in:
viktorstrate
2020-03-12 13:26:11 +01:00
parent bdec205031
commit 7b3f016a0f
5 changed files with 811 additions and 1119 deletions

22
api/utils/Throttle.go Normal file
View File

@@ -0,0 +1,22 @@
package utils
import "time"
type Throttle struct {
interval time.Duration
lastAction time.Time
}
func NewThrottle(interval time.Duration) Throttle {
return Throttle{
interval: interval,
lastAction: time.Unix(0, 0),
}
}
func (t *Throttle) Trigger(action func()) {
if time.Now().After(t.lastAction.Add(t.interval)) {
t.lastAction = time.Now()
action()
}
}