Skip to content
Snippets Groups Projects
Commit 1300de73 authored by Thibaut Barrère's avatar Thibaut Barrère
Browse files

Support optional listener args (to get latency 0 support)

parent d457514a
Branches
No related tags found
No related merge requests found
......@@ -60,6 +60,18 @@ 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:
```elixir
use ExFSWatch, dirs: ["/tmp/fswatch"], listener_extra_args: "--latency=0.0"
```
See the [fs source](https://github.com/synrc/fs/tree/master/c_src) for more details.
## List Events from Backend
```shell
......
require Logger
defmodule ExFSWatch do
defmacro __using__([dirs: dirs]) do
defmacro __using__(options) do
quote do
def __dirs__, do: unquote(dirs)
def __dirs__, do: unquote(Keyword.fetch!(options, :dirs))
def __listener_extra_args__, do: unquote(Keyword.get(options, :listener_extra_args, ''))
def start, do: ExFSWatch.Supervisor.start_child __MODULE__
end
end
......
......@@ -9,7 +9,7 @@ defmodule ExFSWatch.Worker do
def init(module) do
backend = ExFSWatch.backend
port = start_port(backend, module.__dirs__)
port = start_port(backend, module.__dirs__, module.__listener_extra_args__)
{:ok, %__MODULE__{port: port, backend: backend, module: module}}
end
......@@ -29,15 +29,16 @@ defmodule ExFSWatch.Worker do
end
defp start_port(:fsevents, path) do
defp start_port(:fsevents, path, listener_extra_args) do
path = path |> format_path
args = [ listener_extra_args, '-F' | path]
Port.open({:spawn_executable, :fsevents.find_executable()},
[:stream, :exit_status, {:line, 16384}, {:args, ['-F' | path]}, {:cd, System.tmp_dir!}]
[:stream, :exit_status, {:line, 16384}, {:args, args}, {:cd, System.tmp_dir!}]
)
end
defp start_port(:inotifywait, path) do
defp start_port(:inotifywait, path, listener_extra_args) do
path = path |> format_path
args = [ '-c', 'inotifywait $0 $@ & PID=$!; read a; kill $PID',
args = [ listener_extra_args, '-c', 'inotifywait $0 $@ & PID=$!; read a; kill $PID',
'-m', '-e', 'close_write', '-e', 'moved_to', '-e', 'create', '-e',
'delete_self', '-e', 'delete', '-r' | path
]
......@@ -45,9 +46,9 @@ defmodule ExFSWatch.Worker do
[:stream, :exit_status, {:line, 16384}, {:args, args}, {:cd, System.tmp_dir!}]
)
end
defp start_port(:"inotifywait_win32", path) do
defp start_port(:"inotifywait_win32", path, listener_extra_args) do
path = path |> format_path
args = ['-m', '-r' | path]
args = [ listener_extra_args, '-m', '-r' | path]
Port.open({:spawn_executable, :"inotifywait_win32".find_executable()},
[:stream, :exit_status, {:line, 16384}, {:args, args}, {:cd, System.tmp_dir!}]
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment