Skip to content

Commit

Permalink
Deprecates Poolex.get_state in favor of :sys.get_state
Browse files Browse the repository at this point in the history
  • Loading branch information
hissssst committed Nov 16, 2024
1 parent 14945ba commit d2af3f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 27 deletions.
29 changes: 6 additions & 23 deletions lib/poolex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,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.Private.State{worker_module: worker_module} = Poolex.get_state(:my_pool)
iex> %Poolex.Private.State{worker_module: worker_module} = :sys.get_state(:my_pool)
iex> worker_module
Agent
"""
Expand All @@ -119,7 +119,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.Private.State{worker_module: worker_module} = Poolex.get_state(:other_pool)
iex> %Poolex.Private.State{worker_module: worker_module} = :sys.get_state(:other_pool)
iex> worker_module
Agent
"""
Expand Down Expand Up @@ -204,23 +204,10 @@ defmodule Poolex do
end
end

@doc """
Returns current state of started pool.
Primarily needed to help with debugging. **Avoid using this function in production.**
## Examples
iex> Poolex.start(pool_id: :my_pool_2, worker_module: Agent, worker_args: [fn -> 0 end], workers_count: 5)
iex> state = %Poolex.Private.State{} = Poolex.get_state(:my_pool_2)
iex> state.worker_module
Agent
iex> is_pid(state.supervisor)
true
"""
@spec get_state(pool_id()) :: State.t()
def get_state(pool_id) do
GenServer.call(pool_id, :get_state)
@deprecated "Use :sys.get_state/1 instead"
@doc false
def get_state(name) do
:sys.get_state(name)
end

@doc """
Expand Down Expand Up @@ -387,10 +374,6 @@ defmodule Poolex do
end
end

def handle_call(:get_state, _from, state) do
{:reply, state, state}
end

def handle_call(:get_debug_info, _from, %State{} = state) do
debug_info = %DebugInfo{
busy_workers_count: BusyWorkers.count(state),
Expand Down
8 changes: 4 additions & 4 deletions test/poolex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ defmodule PoolexTest do
pool_name = start_pool(worker_module: SomeWorker, workers_count: 1)
pool_pid = Process.whereis(pool_name)

state = Poolex.get_state(pool_name)
state = :sys.get_state(pool_name)

supervisor_pid = state.supervisor
{:ok, worker_pid} = Poolex.run(pool_name, fn pid -> pid end)
Expand All @@ -559,7 +559,7 @@ defmodule PoolexTest do
pool_name = start_pool(worker_module: SomeWorker, workers_count: 1)
pool_pid = Process.whereis(pool_name)

state = Poolex.get_state(pool_name)
state = :sys.get_state(pool_name)

supervisor_pid = state.supervisor
{:ok, worker_pid} = Poolex.run(pool_name, fn pid -> pid end)
Expand Down Expand Up @@ -660,7 +660,7 @@ defmodule PoolexTest do
]}
)

state = Poolex.get_state({:global, :biba})
state = :sys.get_state({:global, :biba})

assert state.pool_id == {:global, :biba}

Expand All @@ -673,7 +673,7 @@ defmodule PoolexTest do

ExUnit.Callbacks.start_supervised({Poolex, [pool_id: name, worker_module: SomeWorker, workers_count: 5]})

state = Poolex.get_state(name)
state = :sys.get_state(name)

assert state.pool_id == name

Expand Down

0 comments on commit d2af3f0

Please sign in to comment.