ExFSWatch
A file change watcher wrapper based on fs
System Support
Just like fs
- Mac fsevent
- Linux inotify
- Windows inotify-win (untested)
NOTE: On Linux you need to install inotify-tools.
Usage
Put exfswatch
in the deps
and application
part of your mix.exs
defmodule Excellent.Mixfile do
use Mix.Project
def project do
...
end
def application do
[applications: [:exfswatch, :logger]]
end
defp deps do
[
{ :exfswatch, "~> 0.4.2", only: :test },
]
end
...
end
write lib/monitor.ex
defmodule Monitor do
use ExFSWatch, dirs: ["/tmp/fswatch"]
def callback(:stop) do
IO.puts "STOP"
end
def callback(file_path, events) do
IO.inspect {file_path, events}
end
end
Execute in iex
iex > Monitor.start
Tweaking behaviour via listener extra arguments
For each platform, you can pass extra arguments to the underlying listener process via the listener_extra_args
option.
Here is an example to get instant notifications on file changes for Mac OS X:
use ExFSWatch, dirs: ["/tmp/fswatch"], listener_extra_args: "--latency=0.0"
See the fs source for more details.
List Events from Backend
iex > ExFSWatch.known_events
TODO
- GenEvent mode
- Unit Testing