From b4c8f5a0fe26604775920318f58fdd3cbdca1d36 Mon Sep 17 00:00:00 2001 From: Teddy Sommavilla Date: Tue, 22 Apr 2025 11:29:31 +0200 Subject: [PATCH] refactor(fsnotifyext): handle Deduper timers in own goroutine, avoid mutex use --- internal/fsnotifyext/fsnotify_dedup.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/internal/fsnotifyext/fsnotify_dedup.go b/internal/fsnotifyext/fsnotify_dedup.go index ef9fa9cb..3c26be66 100644 --- a/internal/fsnotifyext/fsnotify_dedup.go +++ b/internal/fsnotifyext/fsnotify_dedup.go @@ -2,7 +2,6 @@ package fsnotifyext import ( "math" - "sync" "time" "github.com/fsnotify/fsnotify" @@ -11,7 +10,6 @@ import ( type Deduper struct { w *fsnotify.Watcher waitTime time.Duration - mutex sync.Mutex } func NewDeduper(w *fsnotify.Watcher, waitTime time.Duration) *Deduper { @@ -23,9 +21,9 @@ func NewDeduper(w *fsnotify.Watcher, waitTime time.Duration) *Deduper { func (d *Deduper) GetChan() chan fsnotify.Event { channel := make(chan fsnotify.Event) - timers := make(map[string]*time.Timer) go func() { + timers := make(map[string]*time.Timer) for { event, ok := <-d.w.Events switch { @@ -35,17 +33,11 @@ func (d *Deduper) GetChan() chan fsnotify.Event { continue } - d.mutex.Lock() timer, ok := timers[event.String()] - d.mutex.Unlock() - if !ok { timer = time.AfterFunc(math.MaxInt64, func() { channel <- event }) timer.Stop() - - d.mutex.Lock() timers[event.String()] = timer - d.mutex.Unlock() } timer.Reset(d.waitTime)