howeyc / fsnotify

File system notification for Go
BSD 3-Clause "New" or "Revised" License
1.99k stars 252 forks source link

Single vs multiple instance(s) of watcher(s) #87

Closed elgs closed 10 years ago

elgs commented 10 years ago

If I have multiple directories to watch, the directories may be physically located across different disks, or partitions? Should I use only one instance of watcher, created by watcher, _ := fsnotify.NewWatcher(), or should I create separate watchers for each directory?

Thanks, Elgs

elgs commented 10 years ago

I have only one instance of the watcher to watch multiple directories now, including the recursive sub directories. Looks like it works without any problem. By the way, currently I have moved my fsnotify related project from Mac to Linux (in Parallels). Everything seems to be perfect on Linux, however, the one on Mac is not usable now.

elgs commented 10 years ago

I finally chose multiple instances for the reason that if I use only one instance, anything happens in any watched directory will trigger the watcher. This itself is not a problem. However, the reality is that I share the same watcher in multiple goroutines, but I don't want all goroutines to be alerted if only one watched changes. So I finally decided to get each goroutine own its own watcher.