-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/v1.1.0' into main
- Loading branch information
Showing
14 changed files
with
137 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Used by "mix format" | ||
[ | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"], | ||
plugins: [Styler] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,26 @@ | ||
defmodule Poolex.Private.Monitoring do | ||
@moduledoc false | ||
@type kind_of_process() :: :worker | :waiting_caller | ||
|
||
@spec init() :: {:ok, pid()} | ||
@doc """ | ||
Create new monitoring references storage. | ||
""" | ||
def init do | ||
Agent.start_link(fn -> %{} end) | ||
end | ||
alias Poolex.Private.State | ||
|
||
@spec stop(pid()) :: :ok | ||
@doc """ | ||
Delete storage. | ||
""" | ||
def stop(pid) do | ||
Agent.stop(pid) | ||
end | ||
@type kind_of_process() :: :worker | :waiting_caller | ||
|
||
@spec add(monitor_pid :: pid(), worker_pid :: pid(), kind_of_process()) :: :ok | ||
@spec add(State.t(), worker_pid :: pid(), kind_of_process()) :: State.t() | ||
@doc """ | ||
Start monitoring given worker or caller process. | ||
""" | ||
def add(monitor_pid, process_pid, kind_of_process) do | ||
def add(%{monitors: monitors} = state, process_pid, kind_of_process) do | ||
reference = Process.monitor(process_pid) | ||
|
||
Agent.update(monitor_pid, fn state -> Map.put(state, reference, kind_of_process) end) | ||
%{state | monitors: Map.put(monitors, reference, kind_of_process)} | ||
end | ||
|
||
@spec remove(monitor_pid :: pid(), reference()) :: kind_of_process() | ||
@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(monitor_pid, monitoring_reference) do | ||
def remove(%{monitors: monitors} = state, monitoring_reference) do | ||
true = Process.demonitor(monitoring_reference) | ||
|
||
Agent.get_and_update(monitor_pid, fn state -> | ||
{Map.get(state, monitoring_reference), Map.delete(state, monitoring_reference)} | ||
end) | ||
kind_of_process = Map.get(monitors, monitoring_reference) | ||
state = %{state | monitors: Map.delete(monitors, monitoring_reference)} | ||
{kind_of_process, state} | ||
end | ||
end |
Oops, something went wrong.