From efbfbb49f97444c392bc4dc640feb0026c2e52ec Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 Apr 2026 12:53:53 +0530 Subject: [PATCH] Use a single go routine to watch all dirs --- tools/watch/api.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tools/watch/api.go b/tools/watch/api.go index b6de6e999..35e9056f5 100644 --- a/tools/watch/api.go +++ b/tools/watch/api.go @@ -22,11 +22,14 @@ import ( var _ = fmt.Print // watch_dir starts fswatcher in a background goroutine and pipes events to a custom channel. -func watch_dir(ctx context.Context, path string, debounce time.Duration, eventChan chan<- fswatcher.WatchEvent) error { - w, err := fswatcher.New( - fswatcher.WithPath(path), +func watch_dirs(ctx context.Context, paths []string, debounce time.Duration, eventChan chan<- fswatcher.WatchEvent) error { + opts := []fswatcher.WatcherOpt{ fswatcher.WithCooldown(debounce), - ) + } + for _, path := range paths { + opts = append(opts, fswatcher.WithPath(path)) + } + w, err := fswatcher.New(opts...) if err != nil { return err } @@ -108,10 +111,9 @@ func watch_for_kitty_config_changes(action func() error, debounce_time time.Dura } return nil } - for _, path := range dirs_to_watch { - if err := watch_dir(ctx, path, debounce_time, event_chan); err != nil { - return err - } + + if err := watch_dirs(ctx, dirs_to_watch, debounce_time, event_chan); err != nil { + return err } stdinClosed := make(chan struct{}) go func() {