21 lines
536 B
Elixir
21 lines
536 B
Elixir
defmodule Sunbeam.ChannelSupervisor do
|
|
use DynamicSupervisor
|
|
|
|
# NOTE: Also creates a new channel if it dosent exist
|
|
def get(name) do
|
|
case DynamicSupervisor.start_child(__MODULE__, {Sunbeam.Channel, name}) do
|
|
{:ok, pid} -> {:ok, pid}
|
|
{:error, {:already_started, pid}} -> {:ok, pid}
|
|
error -> error
|
|
end
|
|
end
|
|
|
|
def start_link(init) do
|
|
DynamicSupervisor.start_link(__MODULE__, init, name: __MODULE__)
|
|
end
|
|
|
|
@impl true
|
|
def init(_init) do
|
|
DynamicSupervisor.init(strategy: :one_for_one)
|
|
end
|
|
end
|