From 9237967fff641061cb70b0b36dc6b05022bd15ce Mon Sep 17 00:00:00 2001 From: XiShiLong <1050201327@qq.com> Date: Thu, 2 Jun 2022 18:00:10 +0800 Subject: [PATCH] To avoid turning off the listener and restarting the listening service, you need to re-create the object Turning on the listening service again after closing the listening service with the same object will panic because the close method does not re-add the wait list --- watcher.go | 1 + 1 file changed, 1 insertion(+) diff --git a/watcher.go b/watcher.go index 4da4dfe..e218959 100644 --- a/watcher.go +++ b/watcher.go @@ -709,6 +709,7 @@ func (w *Watcher) Close() { w.running = false w.files = make(map[string]os.FileInfo) w.names = make(map[string]bool) + w.wg.Add(1) w.mu.Unlock() // Send a close signal to the Start method. w.close <- struct{}{}