andreaskoch / go-fswatch

fswatch is a go library for monitoring filesystem changes that does not depend on inotify
Other
57 stars 9 forks source link

Folder watching documentation appears to be inaccurate #2

Closed danielsamuels closed 9 years ago

danielsamuels commented 9 years ago

Judging by the actual code, it seems like there was an API change without the folderWatcher examples in the documentation being updated.

andreaskoch commented 9 years ago

Hi Daniel, thanks for pointing that out. I changed the method signatures a while ago and must have forgotten to update the documentation. I will fix that by tomorrow.

Greetings

andreaskoch commented 9 years ago

I have updated the README and the code comments (see: ecea47604a702853c881a7dd161fead47ce8467f).

You can see a working example in the live-reload feature of my markdown webserver "allmark" at github.com/andreaskoch/allmark/blob/master/src/allmark.io/modules/dataaccess/filesystem/watcher.go:

checkIntervalInSeconds := 1

recurse := true
skipNoFiles := func(path string) bool {
  return false
}

folderWatcher := fswatch.NewFolderWatcher(directoryPath, recurse, skipNoFiles, checkIntervalInSeconds)
folderWatcher.Start()

// the go-routine which waits for changes
go func() {
  running := true
  for running {

    select {
    case <-folderWatcher.Modified():
      backChannel <- true

    case <-folderWatcher.Moved():
      running = false

    case <-folderWatcher.Stopped():
      running = false
    }
  }
}()

Greetings Andy