ChannelWatcher
A GenServer to monitor PIDs and run callbacks when they go down.
This is essentially a slightly improved version of Chris McCord’s answer to a StackOverflow question.
Installation
The package can be installed by adding channel_watcher to your list of dependencies in mix.exs:
def deps do
[
{:channel_watcher, "~> 0.1.0"}
]
endUsage
Drop this in a module for a process you wish to test (such as a Phoenix channel):
:ok = ChannelWatcher.monitor(self(), {__MODULE__, CALLBACK, [ARGS]})
Make sure to replace CALLBACK with an atom of your callback function name, and [ARGS] with a list of arguments to pass to that callback.
The test also shows an example of usage.