From da964a82a3bf10e742aac465bfbe19382f1ef79d Mon Sep 17 00:00:00 2001 From: Mandeep Singh Brar Date: Wed, 25 Sep 2024 09:00:50 +0530 Subject: [PATCH] Added suspend resume functionality --- watcher.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/watcher.go b/watcher.go index 4da4dfe..c27b5ed 100644 --- a/watcher.go +++ b/watcher.go @@ -614,6 +614,10 @@ func (w *Watcher) pollEvents(files map[string]os.FileInfo, evt chan Event, w.mu.Lock() defer w.mu.Unlock() + if !w.running { + return + } + // Store create and remove events for use to check for rename events. creates := make(map[string]os.FileInfo) removes := make(map[string]os.FileInfo) @@ -699,6 +703,18 @@ func (w *Watcher) Wait() { w.wg.Wait() } +func (w *Watcher) Suspend() { + w.mu.Lock() + w.running = false + w.mu.Unlock() +} + +func (w *Watcher) Resume() { + w.mu.Lock() + w.running = true + w.mu.Unlock() +} + // Close stops a Watcher and unlocks its mutex, then sends a close signal. func (w *Watcher) Close() { w.mu.Lock()