From 97aa48402087e1c13189ba0ff635708643a6cdac Mon Sep 17 00:00:00 2001 From: Santiago Tortosa Date: Tue, 8 Apr 2025 15:01:56 +0200 Subject: [PATCH] Monitor Notifications.Listener listen_to process --- lib/event_store/notifications/listener.ex | 10 ++++++++++ 1 file changed, 10 insertions(+) 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