29 lines
645 B
Elixir
29 lines
645 B
Elixir
defmodule Odinsea.Channel.Supervisor do
|
|
@moduledoc """
|
|
Supervisor for game channel servers.
|
|
Each channel is a separate TCP listener.
|
|
"""
|
|
|
|
use Supervisor
|
|
|
|
require Logger
|
|
|
|
def start_link(channel_count) do
|
|
Supervisor.start_link(__MODULE__, channel_count, name: __MODULE__)
|
|
end
|
|
|
|
@impl true
|
|
def init(channel_count) do
|
|
children =
|
|
for i <- 1..channel_count do
|
|
%{
|
|
id: {Odinsea.Channel.Server, i},
|
|
start: {Odinsea.Channel.Server, :start_link, [i]}
|
|
}
|
|
end
|
|
|
|
Logger.info("Starting #{channel_count} game channels")
|
|
Supervisor.init(children, strategy: :one_for_one)
|
|
end
|
|
end
|