diff --git a/lib/event_store/notifications/listener.ex b/lib/event_store/notifications/listener.ex index bb92e8b2..d974ab75 100644 --- a/lib/event_store/notifications/listener.ex +++ b/lib/event_store/notifications/listener.ex @@ -44,6 +44,14 @@ defmodule EventStore.Notifications.Listener do dispatch_events([], state) end + def handle_info({:DOWN, _ref, :process, listen_to, reason}, %{listen_to: listen_to} = state) do + {:stop, reason, state} + end + + def handle_info({:DOWN, _ref, :process, _pid, _reason}, state) do + {:noreply, state} + end + def handle_demand(incoming_demand, %Listener{} = state) do %Listener{demand: pending_demand} = state @@ -63,6 +71,8 @@ defmodule EventStore.Notifications.Listener do {:eventually, ref} -> ref end + Process.monitor(listen_to) + %Listener{state | ref: ref} end