Skip to content

Commit 972de9c

Browse files
committed
chore: replace the recursive call with message call
1 parent 0ca7821 commit 972de9c

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lib/mongo/monitor.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ defmodule Mongo.Monitor do
107107
end
108108

109109
def terminate(reason, %{connection_pid: connection_pid, streaming_pid: streaming_pid}) do
110-
## debug info("Terminating monitor for reason #{inspect reason}")
110+
## debug info("Terminating monitor for reason #{inspect reason}, #{inspect self()}, #{inspect streaming_pid}")
111111

112112
GenServer.stop(connection_pid, reason)
113113
GenServer.stop(streaming_pid, reason)
@@ -208,7 +208,7 @@ defmodule Mongo.Monitor do
208208

209209
case StreamingHelloMonitor.start_link(args) do
210210
{:ok, pid} ->
211-
## debug info("Starting streaming mode")
211+
## debug info("Starting streaming mode: #{inspect self()}")
212212
%{state | mode: :streaming_mode, streaming_pid: pid, heartbeat_frequency_ms: 10_000}
213213

214214
error ->

lib/mongo/streaming_hello_monitor.ex

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ defmodule Mongo.StreamingHelloMonitor do
5454
heartbeat_frequency_ms: heartbeat_frequency_ms,
5555
max_await_time_ms: heartbeat_frequency_ms,
5656
more_to_come: false,
57-
# {processId: <ObjectId>, counter: <int64>},
5857
topology_version: nil,
5958
## options
6059
opts: opts
@@ -84,8 +83,23 @@ defmodule Mongo.StreamingHelloMonitor do
8483
handle_info(:update, state)
8584
end
8685

86+
def handle_info({:EXIT, _pid, reason}, state) do
87+
## debug Logger.warn("Stopped with reason #{inspect reason}")
88+
{:stop, reason, state}
89+
end
90+
8791
def handle_info(:update, state) do
88-
{:noreply, update_server_description(state)}
92+
state = update_server_description(state)
93+
94+
case state.more_to_come do
95+
true ->
96+
send(self(), :update)
97+
98+
false ->
99+
:noop
100+
end
101+
102+
{:noreply, state}
89103
end
90104

91105
##
@@ -99,8 +113,8 @@ defmodule Mongo.StreamingHelloMonitor do
99113

100114
case flags &&& @more_to_come_mask do
101115
@more_to_come_mask ->
102-
state = %{state | more_to_come: true}
103-
update_server_description(state)
116+
## debug info("More to come...")
117+
%{state | more_to_come: true}
104118

105119
_other ->
106120
Process.send_after(self(), :update, state.heartbeat_frequency_ms)

0 commit comments

Comments
 (0)