Packages

Perudex is a library implementing the game Perudo, also known as Dudo or Liar's Dice (which you may have heard of in the Pirates of the Caribbean movie).

Current section

Files

Jump to
perudex lib supervisors notifier_supervisor.ex
Raw

lib/supervisors/notifier_supervisor.ex

defmodule Perudex.Supervisors.NotifierSupervisor do
@moduledoc """
Supervisor for notifications servers
"""
use DynamicSupervisor
def start_link(opts) do
DynamicSupervisor.start_link(__MODULE__, opts, name: service_name(opts))
end
@impl true
def init(_opts) do
DynamicSupervisor.init(strategy: :one_for_one)
end
def start_child(game_id, players) do
Enum.each(players, fn player ->
DynamicSupervisor.start_child(
service_name(game_id),
{Perudex.NotifierServer, {game_id, player}}
)
end)
end
defp service_name(game_id) do
Perudex.service_name({__MODULE__, game_id})
end
end