Packages
forge_sdk
0.37.1
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.7
1.0.6
1.0.4
1.0.4-p1
1.0.4-p0
1.0.3
1.0.2
1.0.2-p1
1.0.1
1.0.1-p1
1.0.0
0.40.6
0.40.5
0.40.4
0.40.3
0.40.2
0.40.1
0.40.0
0.39.1
0.39.0
0.38.6
0.38.5
0.38.4
0.38.3
0.38.2
0.38.1
0.38.0
0.37.5
0.37.4
0.37.3
0.37.2
0.37.1
0.37.0
0.34.0
0.33.2
0.33.1
0.33.0
0.32.2
0.32.1
0.32.0
0.31.1
0.31.0
0.30.0
0.29.1
0.29.0
0.28.3
0.28.2
0.28.1
0.28.0
0.27.4
0.27.3
0.27.2
0.27.1
0.27.0
0.26.6
0.26.5
0.26.4
0.26.3
0.26.1
0.26.0
Elixir / Erlang version of the SDK for Forge framework.
Current section
Files
Jump to
Current section
Files
lib/forge_sdk/conn/supervisor.ex
defmodule ForgeSdk.ConnSupervisor do
@moduledoc """
Supervise the connections.
"""
use DynamicSupervisor
alias ForgeSdk.RpcConn
def start_link(_arg) do
DynamicSupervisor.start_link(__MODULE__, [], name: __MODULE__)
end
def init([]) do
DynamicSupervisor.init(strategy: :one_for_one)
end
def add(name, addr, callback \\ nil) do
child_spec = %{
id: name,
# disable retry on gun's part to prevent undesired zombie connections
start: {RpcConn, :start_link, [name, addr, [adapter_opts: %{retry: 0}], callback]},
type: :worker,
restart: :permanent,
shutdown: 500
}
DynamicSupervisor.start_child(__MODULE__, child_spec)
end
def remove(pid) do
DynamicSupervisor.terminate_child(__MODULE__, pid)
end
def children do
DynamicSupervisor.which_children(__MODULE__)
end
def get_names do
Enum.map(children(), fn {_, p, _, _} -> p |> Process.info(:registered_name) |> elem(1) end)
end
def count_children do
DynamicSupervisor.count_children(__MODULE__)
end
end