Convert from the retired ExFSWatch to FileSystem

Initial working commit. Use the new GenServer only API.
This commit is contained in:
Jeff Gandt
2017-12-13 09:39:54 -05:00
parent 0ee975cddd
commit 3742caf1b4
4 changed files with 16 additions and 10 deletions

View File

@@ -8,7 +8,7 @@ defmodule ElixirKoans do
worker(Display, []),
worker(Tracker, []),
worker(Runner, []),
worker(Watcher, [])
worker(Watcher, [[]])
]
opts = [strategy: :one_for_one, name: ElixirKoans.Supervisor]

View File

@@ -1,14 +1,21 @@
defmodule Watcher do
use ExFSWatch, dirs: ["lib/koans"]
use GenServer
def start_link do
start()
def start_link(args) do
GenServer.start_link(__MODULE__, args)
end
def callback(file, events) do
def init(args) do
{:ok, watcher_pid} = FileSystem.start_link(dirs: ["lib/koans"])
FileSystem.subscribe(watcher_pid)
{:ok, %{watcher_pid: watcher_pid}}
end
def handle_info({:file_event, watcher_pid, {path, events}}, %{watcher_pid: watcher_pid}=state) do
if Enum.member?(events, :modified) do
file |> normalize |> reload
path |> normalize |> reload
end
{:noreply, state}
end
defp reload(file) do