ConnectionPool.Worker: Open gun conn in continue instead of init
authorhref <href@random.sh>
Tue, 7 Jul 2020 16:56:17 +0000 (18:56 +0200)
committerrinpatch <rinpatch@sdf.org>
Wed, 15 Jul 2020 12:26:35 +0000 (15:26 +0300)
lib/pleroma/gun/connection_pool/worker.ex

index ec050262159b40428b48e84f941eae1a4ab978a0..6ee622fb047ec985b8d96613cd84380ea62fed56 100644 (file)
@@ -9,7 +9,12 @@ defmodule Pleroma.Gun.ConnectionPool.Worker do
   end
 
   @impl true
-  def init([key, uri, opts, client_pid]) do
+  def init([_key, _uri, _opts, _client_pid] = opts) do
+    {:ok, nil, {:continue, {:connect, opts}}}
+  end
+
+  @impl true
+  def handle_continue({:connect, [key, uri, opts, client_pid]}, _) do
     with {:ok, conn_pid} <- Gun.Conn.open(uri, opts),
          Process.link(conn_pid) do
       time = :erlang.monotonic_time(:millisecond)
@@ -21,7 +26,7 @@ defmodule Pleroma.Gun.ConnectionPool.Worker do
 
       send(client_pid, {:conn_pid, conn_pid})
 
-      {:ok,
+      {:noreply,
        %{key: key, timer: nil, client_monitors: %{client_pid => Process.monitor(client_pid)}},
        :hibernate}
     else