Convert from the retired ExFSWatch to FileSystem
Initial working commit. Use the new GenServer only API.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user