gmethvin / directory-watcher

A cross-platform Java recursive directory watcher, with a JNA macOS watcher and Scala better-files integration
Apache License 2.0
264 stars 34 forks source link

initialize state only when watch/watchAsync is called #84

Closed gmethvin closed 1 year ago

gmethvin commented 1 year ago

DirectoryWatcher relies on tracking state of the directories it is watching, which includes the names of files in the directory tree, whether they are directories, and (optionally) file hashes. Currently the initial state is computed in the constructor of DirectoryWatcher, but DirectoryWatcher does not begin updating the watcher state until watch()/watchAsync() is called. This creates a problem if your application creates a DirectoryWatcher instance without immediately using it.

The most reasonable behavior, I think, is to just initialize this state right before you start watching. I can't think of any reason not to do this.