Skip to content

Instantly share code, notes, and snippets.

@thbar
Created October 29, 2016 11:32
Show Gist options
  • Save thbar/1161034c641d32271419bf2e065cc071 to your computer and use it in GitHub Desktop.
Save thbar/1161034c641d32271419bf2e065cc071 to your computer and use it in GitHub Desktop.
Live code reloading with Elixir
# mix run --no-halt reloading.exs
# in music.exs, put:
#
# defmodule Music do
# def version do
# "3"
# end
# end
#
# then tweak it and save, Music will be reloaded dynamically
Code.compiler_options(ignore_module_conflict: true)
defmodule Monitor do
# relies on https://github.com/falood/exfswatch/pull/9 for --latency support
use ExFSWatch, dirs: ["music.exs"], listener_extra_args: "--latency=0.0"
def callback(_file_path, _events) do
Code.eval_file("music.exs")
IO.inspect Music.version
end
end
Monitor.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment