Watcher
Watcher will monitor a GenEvent manager and a handler. If any of them die the watcher will stop.
If added on a supervision tree the watcher will restart, add the handler and keep processing events.
Why?
https://github.com/elixir-lang/elixir/issues/2662
Installation
First, add Watcher to your mix.exs dependencies:
def deps do
[{:watcher, "~> 1.0.0"}]
end
and run mix deps.get. Now, list the :watcher application as your application dependency:
def application do
[applications: [:watcher]]
endBasic Usage
Instead of adding a handler with GenEvent.add_handler(manager, handler, args) or GenEvent.add_mon_handler(manager, handler, args) just use
Watcher.start_link(manager, handler, args)Or add to a supervision tree
worker(Watcher, [manager, handler, args])
Watcher will also accept the same options that a GenServer accepts (name, debug, etc)