26 lines
734 B
Elixir
26 lines
734 B
Elixir
defmodule Translator.Watcher do
|
|
use GenServer
|
|
|
|
@spec start_link(any) :: :ignore | {:error, any} | {:ok, pid}
|
|
def start_link(args) do
|
|
GenServer.start_link(__MODULE__, args)
|
|
end
|
|
|
|
@spec init(keyword) :: {:ok, %{watcher_pid: pid}}
|
|
def init(args) do
|
|
{:ok, watcher_pid} = FileSystem.start_link(args)
|
|
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
|
|
# YOUR OWN LOGIC FOR PATH AND EVENTS
|
|
{:noreply, state}
|
|
end
|
|
|
|
def handle_info({:file_event, watcher_pid, :stop}, %{watcher_pid: watcher_pid} = state) do
|
|
# YOUR OWN LOGIC WHEN MONITOR STOP
|
|
{:noreply, state}
|
|
end
|
|
end
|