Current section

Files

Jump to
selecto lib selecto connection_pool runtime.ex
Raw

lib/selecto/connection_pool/runtime.ex

defmodule Selecto.ConnectionPool.Runtime do
@moduledoc false
use Supervisor
@registry Selecto.ConnectionPool.Registry
@manager_supervisor Selecto.ConnectionPool.ManagerSupervisor
@spec start_link(keyword()) :: Supervisor.on_start()
def start_link(opts \\ []) do
Supervisor.start_link(__MODULE__, opts, name: __MODULE__)
end
@spec ensure_started() :: {:ok, pid()} | {:error, term()}
def ensure_started do
case Process.whereis(__MODULE__) do
pid when is_pid(pid) ->
{:ok, pid}
nil ->
case start_link([]) do
{:ok, pid} -> {:ok, pid}
{:error, {:already_started, pid}} -> {:ok, pid}
{:error, _} = error -> error
end
end
end
@impl true
def init(_opts) do
children = [
{Registry, keys: :unique, name: @registry},
{DynamicSupervisor, strategy: :one_for_one, name: @manager_supervisor}
]
Supervisor.init(children, strategy: :one_for_all)
end
end