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()