Skip to content

Commit 7aa509a

Browse files
committed
Use sys:terminate to avoid spawning a task
1 parent bb7e167 commit 7aa509a

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

lib/db_connection/watcher.ex

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ defmodule DBConnection.Watcher do
3838
def handle_info({:DOWN, ref, _, _, _}, {caller_refs, started_refs}) do
3939
case caller_refs do
4040
%{^ref => {_supervisor, started_pid, started_ref}} ->
41-
Task.Supervisor.start_child(DBConnection.Task, fn ->
42-
try do
43-
GenServer.stop(started_pid, :shutdown, :infinity)
44-
catch
45-
:exit, _ -> :ok
46-
end
47-
end)
41+
try do
42+
:sys.terminate(started_pid, :shutdown, :infinity)
43+
catch
44+
:exit, {:noproc, {:sys, :terminate, _}} -> :ok
45+
:exit, {:shutdown, {:sys, :terminate, _}} -> :ok
46+
end
4847

4948
caller_refs = Map.delete(caller_refs, ref)
5049
started_refs = Map.put(started_refs, started_ref, {nil, nil})

0 commit comments

Comments
 (0)