We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2241f04 commit 2363c71Copy full SHA for 2363c71
debounce.go
@@ -81,17 +81,18 @@ func (d *debouncer) add(f func()) {
81
defer d.mu.Unlock()
82
83
if d.timer != nil {
84
- d.calls += 1
85
d.timer.Stop()
86
} else {
87
- d.calls = 1
+ d.calls = 0
+ d.startWait = time.Now()
88
}
89
90
+ d.calls += 1
91
+
92
// If the function has been called more than the limit, or if the wait time
93
// has exceeded the limit, execute the function immediately.
94
if d.callLimitReached() || d.timeLimitReached() {
- d.calls = 0
- d.startWait = time.Now()
95
+ d.timer = nil
96
f()
97
} else { // Otherwise, set a timer to call the function after the specified duration.
98
d.timer = time.AfterFunc(d.after, f)
0 commit comments