Current section

Files

Jump to
live_query lib live_query supervisor.ex
Raw

lib/live_query/supervisor.ex

defmodule LiveQuery.Supervisor do
@moduledoc false
use Supervisor
def start_link(opts) do
name = Access.get(opts, :name, :live_query)
unless is_atom(name) do
raise ArgumentError, "name must be an atom"
end
# This will never result in a memory leak since name is an already existing atom
# and all the atoms we're generating are deterministically derived from name. So,
# we only generate new atoms when we are given a new name atom. As a result, we
# could only generate an unbounded number of atoms if we were given an unbounded
# number of unique names which would mean the caller had a memory leak to begin with.
Supervisor.start_link(
__MODULE__,
%{
registry_name: LiveQuery.Registry.name(name),
pubsub_name: String.to_atom("#{name}.pubsub")
},
[]
)
end
@impl Supervisor
def init(opts) do
children = [
{LiveQuery.Registry, opts},
{LiveQuery.PubSub, opts},
{
PartitionSupervisor,
child_spec: LiveQuery.Proxy.child_spec(opts),
name: LiveQuery.Registry.via(opts.registry_name, :proxies)
}
]
Supervisor.init(children, strategy: :rest_for_one)
end
end