Current section
Files
Jump to
Current section
Files
lib/retort/server/pool.ex
defmodule Retort.Server.Pool do
@moduledoc """
Supervises multiple workers with the same configuration for `Retort.Server.Generic`
"""
use Supervisor
alias Retort.Server
# Callbacks
@doc """
Starts `count` `Retort.Server.Generic` workers passing `worker_state`
"""
@spec init([pos_integer | Server.Generic.t]) :: {:ok, {:supervisor.sup_flags, [Supervisor.Spec.spec]}}
def init([count, worker_state = %Server.Generic{}]) when is_integer(count) do
0..(count - 1)
|> Enum.map(
&worker(
Retort.Server.Generic,
[worker_state],
id: {Retort.Server.Generic, &1}
)
)
|> supervise(strategy: :one_for_one)
end
## Supervisor.Spec.supervisor Callbacks
@doc """
Starts supervising the pool of workers
"""
@spec start_link([non_neg_integer | Server.Generic.t], Supervisor.options) :: Supervisor.on_start
def start_link(arg = [count, %Server.Generic{}], supervisor_options \\ []) when is_integer(count) do
Supervisor.start_link(__MODULE__, arg, supervisor_options)
end
end