Packages
poolex
1.2.0
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.5.0
1.5.0-rc.0
1.4.2
1.4.1
1.4.0
1.3.0
1.2.1
1.2.0
1.1.0
1.0.0
1.0.0-rc.0
0.10.0
0.9.0
0.9.0-rc.2
0.9.0-rc.1
0.9.0-rc.0
0.8.0
0.8.0-rc.1
0.8.0-rc.0
0.7.6
0.7.5
0.7.4
retired
0.7.3
0.7.2
0.7.1
0.7.0
0.6.1
0.6.0
0.5.1
0.5.0
0.4.0
0.3.1
retired
0.3.0
retired
0.2.2
0.2.1
0.2.0
0.1.1
0.1.0
The library for managing pools of workers.
Current section
Files
Jump to
Current section
Files
lib/poolex/private/idle_workers.ex
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