Repository: general-CbIC/poolex
Pull request #57 (2023-08-03 12:16:54)

Refactor workers and callers interfaces
Remove unnecessary functions and make code more readable.


Patch:
diff --git a/lib/poolex.ex b/lib/poolex.ex
index 9a6e312..937680f 100644
--- a/lib/poolex.ex
+++ b/lib/poolex.ex
@@ -27,12 +27,12 @@ defmodule Poolex do
 
   use GenServer, shutdown: :infinity
 
-  alias Poolex.BusyWorkers
-  alias Poolex.DebugInfo
-  alias Poolex.IdleWorkers
-  alias Poolex.Monitoring
-  alias Poolex.State
-  alias Poolex.WaitingCallers
+  alias Poolex.Private.BusyWorkers
+  alias Poolex.Private.DebugInfo
+  alias Poolex.Private.IdleWorkers
+  alias Poolex.Private.Monitoring
+  alias Poolex.Private.State
+  alias Poolex.Private.WaitingCallers
 
   @default_wait_timeout :timer.seconds(5)
   @poolex_options_table """
@@ -96,7 +96,7 @@ defmodule Poolex do
   ## Examples
 
       iex> Poolex.start(pool_id: :my_pool, worker_module: Agent, worker_args: [fn -> 0 end], workers_count: 5)
-      iex> %Poolex.State{worker_module: worker_module} = Poolex.get_state(:my_pool)
+      iex> %Poolex.Private.State{worker_module: worker_module} = Poolex.get_state(:my_pool)
       iex> worker_module
       Agent
   """
@@ -120,7 +120,7 @@ defmodule Poolex do
   ## Examples
 
       iex> Poolex.start_link(pool_id: :other_pool, worker_module: Agent, worker_args: [fn -> 0 end], workers_count: 5)
-      iex> %Poolex.State{worker_module: worker_module} = Poolex.get_state(:other_pool)
+      iex> %Poolex.Private.State{worker_module: worker_module} = Poolex.get_state(:other_pool)
       iex> worker_module
       Agent
   """
@@ -217,7 +217,7 @@ defmodule Poolex do
   ## Examples
 
       iex> Poolex.start(pool_id: :my_pool_2, worker_module: Agent, worker_args: [fn -> 0 end], workers_count: 5)
-      iex> state = %Poolex.State{} = Poolex.get_state(:my_pool_2)
+      iex> state = %Poolex.Private.State{} = Poolex.get_state(:my_pool_2)
       iex> state.worker_module
       Agent
       iex> is_pid(state.supervisor)
@@ -249,7 +249,7 @@ defmodule Poolex do
   ## Examples
 
       iex> Poolex.start(pool_id: :my_pool_3, worker_module: Agent, worker_args: [fn -> 0 end], workers_count: 5)
-      iex> debug_info = %Poolex.DebugInfo{} = Poolex.get_debug_info(:my_pool_3)
+      iex> debug_info = %Poolex.Private.DebugInfo{} = Poolex.get_debug_info(:my_pool_3)
       iex> debug_info.busy_workers_count
       0
       iex> debug_info.idle_workers_count
@@ -279,25 +279,28 @@ defmodule Poolex do
       Keyword.get(opts, :waiting_callers_impl, Poolex.Callers.Impl.ErlangQueue)
 
     {:ok, monitor_id} = Monitoring.init(pool_id)
-    {:ok, supervisor} = Poolex.Supervisor.start_link()
-
-    state = %State{
-      busy_workers_impl: busy_workers_impl,
-      busy_workers_state: BusyWorkers.init(busy_workers_impl),
-      idle_workers_impl: idle_workers_impl,
-      max_overflow: max_overflow,
-      monitor_id: monitor_id,
-      pool_id: pool_id,
-      supervisor: supervisor,
-      waiting_callers_impl: waiting_callers_impl,
-      waiting_callers_state: WaitingCallers.init(waiting_callers_impl),
-      worker_args: worker_args,
-      worker_module: worker_module,
-      worker_start_fun: worker_start_fun
-    }
+    {:ok, supervisor} = Poolex.Private.Supervisor.start_link()
+
+    state =
+      %State{
+        max_overflow: max_overflow,
+        monitor_id: monitor_id,
+        pool_id: pool_id,
+        supervisor: supervisor,
+        worker_args: worker_args,
+        worker_module: worker_module,
+        worker_start_fun: worker_start_fun
+      }
+
+    initial_workers_pids = start_workers(workers_count, state, monitor_id)
 
-    worker_pids = start_workers(workers_count, state, monitor_id)
-    {:ok, %State{state | idle_workers_state: IdleWorkers.init(idle_workers_impl, worker_pids)}}
+    state =
+      state
+      |> IdleWorkers.init(idle_workers_impl, initial_workers_pids)
+      |> BusyWorkers.init(busy_workers_impl)
+      |> WaitingCallers.init(waiting_callers_impl)
+
+    {:ok, state}
   end
 
   @spec start_workers(non_neg_integer(), State.t(), Monitoring.monitor_id()) :: [pid]
@@ -335,32 +338,26 @@ defmodule Poolex do
 
   @impl GenServer
   def handle_call(:get_idle_worker, {from_pid, _} = caller, %State{} = state) do
-    if IdleWorkers.empty?(state.idle_workers_impl, state.idle_workers_state) do
+    if IdleWorkers.empty?(state) do
       if state.overflow < state.max_overflow do
         {:ok, new_worker} = start_worker(state)
 
         Monitoring.add(state.monitor_id, new_worker, :worker)
 
-        state = add_worker_to_busy_workers(state, new_worker)
+        state = BusyWorkers.add(state, new_worker)
 
         {:reply, {:ok, new_worker}, %State{state | overflow: state.overflow + 1}}
       else
         Monitoring.add(state.monitor_id, from_pid, :waiting_caller)
+        state = WaitingCallers.add(state, caller)
 
-        new_callers_state =
-          WaitingCallers.add(state.waiting_callers_impl, state.waiting_callers_state, caller)
-
-        {:noreply, %{state | waiting_callers_state: new_callers_state}}
+        {:noreply, state}
       end
     else
-      {idle_worker_pid, new_idle_workers_state} =
-        IdleWorkers.pop(state.idle_workers_impl, state.idle_workers_state)
+      {idle_worker_pid, state} = IdleWorkers.pop(state)
+      state = BusyWorkers.add(state, idle_worker_pid)
 
-      state = add_worker_to_busy_workers(state, idle_worker_pid)
-
-      new_state = %State{state | idle_workers_state: new_idle_workers_state}
-
-      {:reply, {:ok, idle_worker_pid}, new_state}
+      {:reply, {:ok, idle_worker_pid}, state}
     end
   end
 
@@ -368,18 +365,17 @@ defmodule Poolex do
     {:reply, state, state}
   end
 
-  def handle_call(:get_debug_info, _form, %Poolex.State{} = state) do
+  def handle_call(:get_debug_info, _form, %State{} = state) do
     debug_info = %DebugInfo{
-      busy_workers_count: BusyWorkers.count(state.busy_workers_impl, state.busy_workers_state),
+      busy_workers_count: BusyWorkers.count(state),
       busy_workers_impl: state.busy_workers_impl,
-      busy_workers_pids: BusyWorkers.to_list(state.busy_workers_impl, state.busy_workers_state),
-      idle_workers_count: IdleWorkers.count(state.idle_workers_impl, state.idle_workers_state),
+      busy_workers_pids: BusyWorkers.to_list(state),
+      idle_workers_count: IdleWorkers.count(state),
       idle_workers_impl: state.idle_workers_impl,
-      idle_workers_pids: IdleWorkers.to_list(state.idle_workers_impl, state.idle_workers_state),
+      idle_workers_pids: IdleWorkers.to_list(state),
       max_overflow: state.max_overflow,
       overflow: state.overflow,
-      waiting_callers:
-        WaitingCallers.to_list(state.waiting_callers_impl, state.waiting_callers_state),
+      waiting_callers: WaitingCallers.to_list(state),
       waiting_callers_impl: state.waiting_callers_impl,
       worker_args: state.worker_args,
       worker_module: state.worker_module,
@@ -391,7 +387,7 @@ defmodule Poolex do
 
   @impl GenServer
   def handle_cast({:release_busy_worker, worker}, %State{} = state) do
-    if WaitingCallers.empty?(state.waiting_callers_impl, state.waiting_callers_state) do
+    if WaitingCallers.empty?(state) do
       new_state = release_busy_worker(state, worker)
       {:noreply, new_state}
     else
@@ -416,15 +412,15 @@ defmodule Poolex do
 
   @spec release_busy_worker(State.t(), worker()) :: State.t()
   defp release_busy_worker(%State{} = state, worker) do
-    if BusyWorkers.member?(state.busy_workers_impl, state.busy_workers_state, worker) do
-      state = remove_worker_from_busy_workers(state, worker)
+    if BusyWorkers.member?(state, worker) do
+      state = BusyWorkers.remove(state, worker)
 
       if state.overflow > 0 do
         stop_worker(state.supervisor, worker)
 
         state
       else
-        add_worker_to_idle_workers(state, worker)
+        IdleWorkers.add(state, worker)
       end
     else
       state
@@ -433,74 +429,21 @@ defmodule Poolex do
 
   @spec provide_worker_to_waiting_caller(State.t(), worker()) :: State.t()
   defp provide_worker_to_waiting_caller(%State{} = state, worker) do
-    {caller, new_waiting_callers_state} =
-      WaitingCallers.pop(state.waiting_callers_impl, state.waiting_callers_state)
+    {caller, state} = WaitingCallers.pop(state)
 
     GenServer.reply(caller, {:ok, worker})
 
-    %{state | waiting_callers_state: new_waiting_callers_state}
-  end
-
-  @spec add_worker_to_busy_workers(State.t(), worker()) :: State.t()
-  defp add_worker_to_busy_workers(%State{} = state, worker) do
-    %State{
-      state
-      | busy_workers_state:
-          BusyWorkers.add(
-            state.busy_workers_impl,
-            state.busy_workers_state,
-            worker
-          )
-    }
-  end
-
-  @spec add_worker_to_idle_workers(State.t(), worker()) :: State.t()
-  defp add_worker_to_idle_workers(%State{} = state, worker) do
-    %State{
-      state
-      | idle_workers_state:
-          IdleWorkers.add(
-            state.idle_workers_impl,
-            state.idle_workers_state,
-            worker
-          )
-    }
-  end
-
-  @spec remove_worker_from_busy_workers(State.t(), worker()) :: State.t()
-  defp remove_worker_from_busy_workers(%State{} = state, worker) do
-    %State{
-      state
-      | busy_workers_state:
-          BusyWorkers.remove(
-            state.busy_workers_impl,
-            state.busy_workers_state,
-            worker
-          )
-    }
-  end
-
-  @spec remove_worker_from_idle_workers(State.t(), worker()) :: State.t()
-  defp remove_worker_from_idle_workers(%State{} = state, worker) do
-    %State{
-      state
-      | idle_workers_state:
-          IdleWorkers.remove(
-            state.idle_workers_impl,
-            state.idle_workers_state,
-            worker
-          )
-    }
+    state
   end
 
   @spec handle_down_worker(State.t(), pid()) :: State.t()
   defp handle_down_worker(%State{} = state, dead_process_pid) do
     state =
       state
-      |> remove_worker_from_idle_workers(dead_process_pid)
-      |> remove_worker_from_busy_workers(dead_process_pid)
+      |> IdleWorkers.remove(dead_process_pid)
+      |> BusyWorkers.remove(dead_process_pid)
 
-    if WaitingCallers.empty?(state.waiting_callers_impl, state.waiting_callers_state) do
+    if WaitingCallers.empty?(state) do
       if state.overflow > 0 do
         %State{state | overflow: state.overflow - 1}
       else
@@ -508,28 +451,21 @@ defmodule Poolex do
 
         Monitoring.add(state.monitor_id, new_worker, :worker)
 
-        add_worker_to_idle_workers(state, new_worker)
+        IdleWorkers.add(state, new_worker)
       end
     else
       {:ok, new_worker} = start_worker(state)
       Monitoring.add(state.monitor_id, new_worker, :worker)
 
       state
-      |> add_worker_to_busy_workers(new_worker)
+      |> BusyWorkers.add(new_worker)
       |> provide_worker_to_waiting_caller(new_worker)
     end
   end
 
   @spec handle_down_waiting_caller(State.t(), pid()) :: State.t()
   defp handle_down_waiting_caller(%State{} = state, dead_process_pid) do
-    new_waiting_callers_state =
-      WaitingCallers.remove_by_pid(
-        state.waiting_callers_impl,
-        state.waiting_callers_state,
-        dead_process_pid
-      )
-
-    %State{state | waiting_callers_state: new_waiting_callers_state}
+    WaitingCallers.remove_by_pid(state, dead_process_pid)
   end
 
   @impl GenServer
diff --git a/lib/poolex/busy_workers.ex b/lib/poolex/busy_workers.ex
deleted file mode 100644
index 9cd1288..0000000
--- a/lib/poolex/busy_workers.ex
+++ /dev/null
@@ -1,30 +0,0 @@
-defmodule Poolex.BusyWorkers do
-  @moduledoc false
-  alias Poolex.Workers.Behaviour
-
-  @doc false
-  @spec init(module()) :: Behaviour.state()
-  def init(impl) do
-    impl.init()
-  end
-
-  @doc false
-  @spec add(module(), Behaviour.state(), Poolex.worker()) :: Behaviour.state()
-  def add(impl, state, worker), do: impl.add(state, worker)
-
-  @doc false
-  @spec member?(module(), Behaviour.state(), Poolex.worker()) :: boolean()
-  def member?(impl, state, worker), do: impl.member?(state, worker)
-
-  @doc false
-  @spec remove(module(), Behaviour.state(), Poolex.worker()) :: Behaviour.state()
-  def remove(impl, state, worker), do: impl.remove(state, worker)
-
-  @doc false
-  @spec count(module(), Behaviour.state()) :: non_neg_integer()
-  def count(impl, state), do: impl.count(state)
-
-  @doc false
-  @spec to_list(module(), Behaviour.state()) :: list(Poolex.worker())
-  def to_list(impl, state), do: impl.to_list(state)
-end
diff --git a/lib/poolex/idle_workers.ex b/lib/poolex/idle_workers.ex
deleted file mode 100644
index 7db808a..0000000
--- a/lib/poolex/idle_workers.ex
+++ /dev/null
@@ -1,41 +0,0 @@
-defmodule Poolex.IdleWorkers do
-  @moduledoc false
-  alias Poolex.Workers.Behaviour
-
-  @doc false
-  @spec init(module()) :: Behaviour.state()
-  def init(impl) do
-    impl.init()
-  end
-
-  @doc false
-  @spec init(module(), list(Poolex.worker())) :: Behaviour.state()
-  def init(impl, workers) do
-    impl.init(workers)
-  end
-
-  @doc false
-  @spec add(module(), Behaviour.state(), Poolex.worker()) :: Behaviour.state()
-  def add(impl, state, worker), do: impl.add(state, worker)
-
-  @doc false
-  @spec remove(module(), Behaviour.state(), Poolex.worker()) :: Behaviour.state()
-  def remove(impl, state, worker), do: impl.remove(state, worker)
-
-  @doc false
-  @spec count(module(), Behaviour.state()) :: non_neg_integer()
-  def count(impl, state), do: impl.count(state)
-
-  @doc false
-  @spec to_list(module(), Behaviour.state()) :: list(Poolex.worker())
-  def to_list(impl, state), do: impl.to_list(state)
-
-  @doc false
-  @spec empty?(module(), Behaviour.state()) :: boolean()
-  def empty?(impl, state), do: impl.empty?(state)
-
-  @doc false
-  @spec pop(module(), Behaviour.state()) ::
-          {Poolex.worker(), Behaviour.state()} | :empty
-  def pop(impl, state), do: impl.pop(state)
-end
diff --git a/lib/poolex/private/busy_workers.ex b/lib/poolex/private/busy_workers.ex
new file mode 100644
index 0000000..8801bee
--- /dev/null
+++ b/lib/poolex/private/busy_workers.ex
@@ -0,0 +1,44 @@
+defmodule Poolex.Private.BusyWorkers do
+  @moduledoc false
+
+  alias Poolex.Private.State
+
+  @doc false
+  @spec init(State.t(), busy_workers_impl :: module()) :: State.t()
+  def init(%State{} = state, impl) do
+    %State{state | busy_workers_impl: impl, busy_workers_state: impl.init()}
+  end
+
+  @doc false
+  @spec add(State.t(), Poolex.worker()) :: State.t()
+  def add(%State{busy_workers_impl: impl, busy_workers_state: busy_workers_state} = state, worker) do
+    %State{state | busy_workers_state: impl.add(busy_workers_state, worker)}
+  end
+
+  @doc false
+  @spec member?(State.t(), Poolex.worker()) :: boolean()
+  def member?(%State{busy_workers_impl: impl, busy_workers_state: busy_workers_state}, worker) do
+    impl.member?(busy_workers_state, worker)
+  end
+
+  @doc false
+  @spec remove(State.t(), Poolex.worker()) :: State.t()
+  def remove(
+        %State{busy_workers_impl: impl, busy_workers_state: busy_workers_state} = state,
+        worker
+      ) do
+    %State{state | busy_workers_state: impl.remove(busy_workers_state, worker)}
+  end
+
+  @doc false
+  @spec count(State.t()) :: non_neg_integer()
+  def count(%State{busy_workers_impl: impl, busy_workers_state: state}) do
+    impl.count(state)
+  end
+
+  @doc false
+  @spec to_list(State.t()) :: list(Poolex.worker())
+  def to_list(%State{busy_workers_impl: impl, busy_workers_state: state}) do
+    impl.to_list(state)
+  end
+end
diff --git a/lib/poolex/debug_info.ex b/lib/poolex/private/debug_info.ex
similarity index 96%
rename from lib/poolex/debug_info.ex
rename to lib/poolex/private/debug_info.ex
index 3e45347..bb347b1 100644
--- a/lib/poolex/debug_info.ex
+++ b/lib/poolex/private/debug_info.ex
@@ -1,4 +1,4 @@
-defmodule Poolex.DebugInfo do
+defmodule Poolex.Private.DebugInfo do
   @moduledoc """
   Information with the current state of the pool.
 
diff --git a/lib/poolex/private/idle_workers.ex b/lib/poolex/private/idle_workers.ex
new file mode 100644
index 0000000..3dfcec2
--- /dev/null
+++ b/lib/poolex/private/idle_workers.ex
@@ -0,0 +1,56 @@
+defmodule Poolex.Private.IdleWorkers do
+  @moduledoc false
+
+  alias Poolex.Private.State
+
+  @doc false
+  @spec init(State.t(), idle_workers_impl :: module(), list(Poolex.worker())) :: State.t()
+  def init(%State{} = state, impl, workers) do
+    %State{state | idle_workers_impl: impl, idle_workers_state: impl.init(workers)}
+  end
+
+  @doc false
+  @spec add(State.t(), Poolex.worker()) :: State.t()
+  def add(%State{idle_workers_impl: impl, idle_workers_state: idle_workers_state} = state, worker) do
+    %State{state | idle_workers_state: impl.add(idle_workers_state, worker)}
+  end
+
+  @doc false
+  @spec remove(State.t(), Poolex.worker()) :: State.t()
+  def remove(
+        %State{idle_workers_impl: impl, idle_workers_state: idle_workers_state} = state,
+        worker
+      ) do
+    %State{state | idle_workers_state: impl.remove(idle_workers_state, worker)}
+  end
+
+  @doc false
+  @spec count(State.t()) :: neg_integer()
+  def count(%State{idle_workers_impl: impl, idle_workers_state: state}) do
+    impl.count(state)
+  end
+
+  @doc false
+  @spec to_list(State.t()) :: list(Poolex.worker())
+  def to_list(%State{idle_workers_impl: impl, idle_workers_state: state}) do
+    impl.to_list(state)
+  end
+
+  @doc false
+  @spec empty?(State.t()) :: boolean()
+  def empty?(%State{idle_workers_impl: impl, idle_workers_state: state}) do
+    impl.empty?(state)
+  end
+
+  @doc false
+  @spec pop(State.t()) :: {Poolex.worker(), State.t()} | :empty
+  def pop(%State{idle_workers_impl: impl, idle_workers_state: idle_workers_state} = state) do
+    case impl.pop(idle_workers_state) do
+      {worker, new_idle_workers_state} ->
+        {worker, %State{state | idle_workers_state: new_idle_workers_state}}
+
+      :empty ->
+        :empty
+    end
+  end
+end
diff --git a/lib/poolex/monitoring.ex b/lib/poolex/private/monitoring.ex
similarity index 96%
rename from lib/poolex/monitoring.ex
rename to lib/poolex/private/monitoring.ex
index 9490465..9893472 100644
--- a/lib/poolex/monitoring.ex
+++ b/lib/poolex/private/monitoring.ex
@@ -1,4 +1,4 @@
-defmodule Poolex.Monitoring do
+defmodule Poolex.Private.Monitoring do
   @moduledoc false
   @type monitor_id() :: atom() | reference()
   @type kind_of_process() :: :worker | :waiting_caller
diff --git a/lib/poolex/state.ex b/lib/poolex/private/state.ex
similarity index 97%
rename from lib/poolex/state.ex
rename to lib/poolex/private/state.ex
index b6d5eb5..086a45e 100644
--- a/lib/poolex/state.ex
+++ b/lib/poolex/private/state.ex
@@ -1,4 +1,4 @@
-defmodule Poolex.State do
+defmodule Poolex.Private.State do
   @moduledoc """
   Internal structure containing the state of the pool.
 
diff --git a/lib/poolex/supervisor.ex b/lib/poolex/private/supervisor.ex
similarity index 87%
rename from lib/poolex/supervisor.ex
rename to lib/poolex/private/supervisor.ex
index a238281..da24a9e 100644
--- a/lib/poolex/supervisor.ex
+++ b/lib/poolex/private/supervisor.ex
@@ -1,4 +1,4 @@
-defmodule Poolex.Supervisor do
+defmodule Poolex.Private.Supervisor do
   @moduledoc false
   use DynamicSupervisor
 
diff --git a/lib/poolex/private/waiting_callers.ex b/lib/poolex/private/waiting_callers.ex
new file mode 100644
index 0000000..1feb43b
--- /dev/null
+++ b/lib/poolex/private/waiting_callers.ex
@@ -0,0 +1,55 @@
+defmodule Poolex.Private.WaitingCallers do
+  @moduledoc false
+
+  alias Poolex.Private.State
+
+  @doc false
+  @spec init(State.t(), waiting_callers_impl :: module()) :: State.t()
+  def init(%State{} = state, impl) do
+    %State{state | waiting_callers_impl: impl, waiting_callers_state: impl.init()}
+  end
+
+  @doc false
+  @spec add(State.t(), Poolex.caller()) :: State.t()
+  def add(
+        %State{waiting_callers_impl: impl, waiting_callers_state: waiting_callers_state} = state,
+        caller
+      ) do
+    %State{state | waiting_callers_state: impl.add(waiting_callers_state, caller)}
+  end
+
+  @doc false
+  @spec empty?(State.t()) :: boolean()
+  def empty?(%State{waiting_callers_impl: impl, waiting_callers_state: state}) do
+    impl.empty?(state)
+  end
+
+  @doc false
+  @spec pop(State.t()) :: {Poolex.caller(), State.t()} | :empty
+  def pop(
+        %State{waiting_callers_impl: impl, waiting_callers_state: waiting_callers_state} = state
+      ) do
+    case impl.pop(waiting_callers_state) do
+      {caller, new_waiting_callers_state} ->
+        {caller, %State{state | waiting_callers_state: new_waiting_callers_state}}
+
+      :empty ->
+        :empty
+    end
+  end
+
+  @doc false
+  @spec remove_by_pid(State.t(), caller_pid :: pid()) :: State.t()
+  def remove_by_pid(
+        %State{waiting_callers_impl: impl, waiting_callers_state: waiting_callers_state} = state,
+        caller
+      ) do
+    %State{state | waiting_callers_state: impl.remove_by_pid(waiting_callers_state, caller)}
+  end
+
+  @doc false
+  @spec to_list(State.t()) :: list(Poolex.caller())
+  def to_list(%State{waiting_callers_impl: impl, waiting_callers_state: state}) do
+    impl.to_list(state)
+  end
+end
diff --git a/lib/poolex/waiting_callers.ex b/lib/poolex/waiting_callers.ex
deleted file mode 100644
index 70a2d9e..0000000
--- a/lib/poolex/waiting_callers.ex
+++ /dev/null
@@ -1,33 +0,0 @@
-defmodule Poolex.WaitingCallers do
-  @moduledoc false
-  alias Poolex.Callers.Behaviour
-
-  @doc false
-  @spec init(module()) :: Behaviour.state()
-  def init(impl) do
-    impl.init()
-  end
-
-  @doc false
-  @spec add(module(), Behaviour.state(), Poolex.caller()) :: Behaviour.state()
-  def add(impl, state, caller), do: impl.add(state, caller)
-
-  @doc false
-  @spec empty?(module(), Behaviour.state()) :: boolean()
-  def empty?(impl, state), do: impl.empty?(state)
-
-  @doc false
-  @spec pop(module(), Behaviour.state()) ::
-          {Poolex.caller(), Behaviour.state()} | :empty
-  def pop(impl, state), do: impl.pop(state)
-
-  @doc false
-  @spec remove_by_pid(module(), Behaviour.state(), pid()) :: Behaviour.state()
-  def remove_by_pid(impl, state, caller_pid) do
-    impl.remove_by_pid(state, caller_pid)
-  end
-
-  @doc false
-  @spec to_list(module(), Behaviour.state()) :: list(Poolex.caller())
-  def to_list(impl, state), do: impl.to_list(state)
-end


Test patch:
diff --git a/test/poolex_test.exs b/test/poolex_test.exs
index 8f0de67..9911cc0 100644
--- a/test/poolex_test.exs
+++ b/test/poolex_test.exs
@@ -10,7 +10,7 @@ defmodule PoolexTest do
 
       debug_info = Poolex.get_debug_info(pool_name)
 
-      assert debug_info.__struct__ == Poolex.DebugInfo
+      assert debug_info.__struct__ == Poolex.Private.DebugInfo
       assert debug_info.busy_workers_count == 0
       assert debug_info.busy_workers_impl == Poolex.Workers.Impl.List
       assert debug_info.busy_workers_pids == []
@@ -49,7 +49,7 @@ defmodule PoolexTest do
 
       debug_info = Poolex.get_debug_info(pool_name)
 
-      assert debug_info.__struct__ == Poolex.DebugInfo
+      assert debug_info.__struct__ == Poolex.Private.DebugInfo
       assert debug_info.busy_workers_count == 0
       assert Enum.empty?(debug_info.busy_workers_pids)
       assert debug_info.idle_workers_count == 5
@@ -78,7 +78,7 @@ defmodule PoolexTest do
 
       debug_info = Poolex.get_debug_info(pool_name)
 
-      assert debug_info.__struct__ == Poolex.DebugInfo
+      assert debug_info.__struct__ == Poolex.Private.DebugInfo
       assert debug_info.busy_workers_count == 1
       assert Enum.count(debug_info.busy_workers_pids) == 1
       assert debug_info.idle_workers_count == 4