fix previous commit: make it compatible with old go version

This commit is contained in:
Samuel Berthe
2025-07-06 18:16:41 +02:00
parent 308ce769cf
commit 69cd99225d

View File

@@ -3,8 +3,6 @@ package lo
import ( import (
"sync" "sync"
"time" "time"
"golang.org/x/exp/slices"
) )
type debounce struct { type debounce struct {
@@ -30,7 +28,7 @@ func (d *debounce) reset() {
d.timer = time.AfterFunc(d.after, func() { d.timer = time.AfterFunc(d.after, func() {
// We need to lock the mutex here to avoid race conditions with 2 concurrent calls to reset() // We need to lock the mutex here to avoid race conditions with 2 concurrent calls to reset()
d.mu.Lock() d.mu.Lock()
callbacks := slices.Clone(d.callbacks) callbacks := append([]func(){}, d.callbacks...)
d.mu.Unlock() d.mu.Unlock()
for i := range callbacks { for i := range callbacks {
@@ -107,7 +105,7 @@ func (d *debounceBy[T]) reset(key T) {
item.mu.Lock() item.mu.Lock()
count := item.count count := item.count
item.count = 0 item.count = 0
callbacks := slices.Clone(d.callbacks) callbacks := append([]func(key T, count int){}, d.callbacks...)
item.mu.Unlock() item.mu.Unlock()
for i := range callbacks { for i := range callbacks {