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/monitoring.ex
defmodule Poolex.Private.Monitoring do
@moduledoc false
alias Poolex.Private.State
@type kind_of_process() :: :worker | :waiting_caller
@spec add(State.t(), worker_pid :: pid(), kind_of_process()) :: State.t()
@doc """
Start monitoring given worker or caller process.
"""
def add(%{monitors: monitors} = state, process_pid, kind_of_process) do
reference = Process.monitor(process_pid)
%{state | monitors: Map.put(monitors, reference, kind_of_process)}
end
@spec remove(State.t(), reference()) :: {kind_of_process(), State.t()}
@doc """
Stop monitoring given worker or caller process and return kind of it.
"""
def remove(%{monitors: monitors} = state, monitoring_reference) do
true = Process.demonitor(monitoring_reference)
kind_of_process = Map.get(monitors, monitoring_reference)
state = %{state | monitors: Map.delete(monitors, monitoring_reference)}
{kind_of_process, state}
end
end