init: inital commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
defmodule Localiser.Localisation.Floor.Supervisor do
|
||||
use DynamicSupervisor
|
||||
|
||||
alias Localiser.Domain.Floors
|
||||
alias Localiser.Localisation.Floor.Server
|
||||
|
||||
def start_link(_args) do
|
||||
case DynamicSupervisor.start_link(__MODULE__, :ok, name: __MODULE__) do
|
||||
{:ok, pid} ->
|
||||
Floors.list_floors() |> Enum.each(&start_floor_server/1)
|
||||
{:ok, pid}
|
||||
|
||||
error ->
|
||||
error
|
||||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
def init(:ok) do
|
||||
DynamicSupervisor.init(strategy: :one_for_one)
|
||||
end
|
||||
|
||||
def start_floor_server(floor) do
|
||||
child_spec = %{
|
||||
id: {Server, floor.id},
|
||||
start: {Server, :start_link, [floor]},
|
||||
restart: :transient
|
||||
}
|
||||
|
||||
DynamicSupervisor.start_child(__MODULE__, child_spec)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user