26 lines
590 B
Elixir
26 lines
590 B
Elixir
defmodule Todo.Cache do
|
|
use DynamicSupervisor
|
|
|
|
def start_link(init_arg) do
|
|
IO.puts("Starting #{__MODULE__}")
|
|
|
|
DynamicSupervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
|
|
end
|
|
|
|
@impl DynamicSupervisor
|
|
def init(_) do
|
|
DynamicSupervisor.init(strategy: :one_for_one)
|
|
end
|
|
|
|
def server_process(todo_list_name) do
|
|
case start_child(todo_list_name) do
|
|
{:ok, pid} -> pid
|
|
{:error, {:already_started, pid}} -> pid
|
|
end
|
|
end
|
|
|
|
defp start_child(todo_list_name) do
|
|
DynamicSupervisor.start_child(__MODULE__, {Todo.Server, todo_list_name})
|
|
end
|
|
end
|