Detect when I save a code file def init(args) do {:ok, watcher_pid} = FileSystem.start_link(args) FileSystem.subscribe(watcher_pid) def handle_info({:file_event, watcher_pid, {path, events}}, state) do do IO.puts "The file at #{path} has changed!" {:noreply, state} end
Re-evaluate it at runtime (hot reloading) def handle_info({:file_event, watcher_pid, {path, events}}, state) do do Code.eval_file(path) {:noreply, state} end
AHA MOMENT GenServer reloading keeps the state across reloads. => We can keep the "current music position/tick" between reloads. defmodule Artist do use GenServer def handle_info(:tick, state) do Process.send_after(self(), :tick, @tick_period)