Skip to content

Commit

Permalink
Reset calledDuringExecution right before executing function
Browse files Browse the repository at this point in the history
  • Loading branch information
chdxD1 committed Jul 5, 2023
1 parent 6f13d58 commit 5670445
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions pkg/debounce/debounce.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (d *Debouncer) debounceRoutine(ctx context.Context) {
for {
// First sleep for the debounceTime
time.Sleep(d.debounceTime)

d.calledDuringExecution.Store(false)
err := d.function(ctx)
if err == nil {
// If debounce was called during execution run debounceRoutine again otherwise reset
Expand All @@ -58,7 +58,6 @@ func (d *Debouncer) Debounce(ctx context.Context) {
// be true) will run the debounced routine once again
d.calledDuringExecution.Store(true)
if d.scheduled.CompareAndSwap(false, true) {
d.calledDuringExecution.Store(false)
go d.debounceRoutine(ctx)
}
}

0 comments on commit 5670445

Please sign in to comment.