Drone. Swarm. Supervisor
(ex_drone v0.3.0)
View Source
Dynamic supervisor for Drone.Swarm coordinator processes.
Vehicles remain under Drone.Supervisor. This supervisor only owns
swarm coordinators so a swarm crash does not restart vehicle children
(and vice versa).
Started automatically by the application supervisor as Drone.Swarm.Supervisor.
Example
Prefer Drone.Swarm.start/1, which uses this supervisor:
{:ok, swarm} =
Drone.Swarm.start(
name: :demo,
members: [{:a, adapter: :sim}, {:b, adapter: :sim}]
)
Summary
Functions
Returns a specification to start this module under a supervisor.
Initializes the supervisor with a :one_for_one strategy.
Starts the swarm dynamic supervisor (named Drone.Swarm.Supervisor).
Starts a Drone.Swarm child under this supervisor.
Terminates a swarm coordinator by pid.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Initializes the supervisor with a :one_for_one strategy.
Parameters
_opts(term()) — start options (ignored)
Returns
{:ok, DynamicSupervisor.sup_flags()}
@spec start_link(keyword()) :: GenServer.on_start()
Starts the swarm dynamic supervisor (named Drone.Swarm.Supervisor).
Parameters
opts(keyword()) — passed toDynamicSupervisor.start_link/3(normally unused; the process is named)
Returns
Standard GenServer.on_start() result.
Example
# Child of the OTP application:
# {Drone.Swarm.Supervisor, []}
@spec start_swarm(keyword()) :: DynamicSupervisor.on_start_child()
Starts a Drone.Swarm child under this supervisor.
Prefer Drone.Swarm.start/1, which wraps this call and returns a
swarm handle (name or pid).
Parameters
opts(keyword()) — normalized swarm options including:members
Returns
DynamicSupervisor.on_start_child() — typically {:ok, pid} or
{:error, reason}.
Example
{:ok, pid} =
Drone.Swarm.Supervisor.start_swarm(
name: :patrol,
members: [{:a, adapter: :sim}, {:b, adapter: :sim}]
)
@spec stop_swarm(pid()) :: :ok | {:error, :not_found}
Terminates a swarm coordinator by pid.
Because the swarm traps exits, termination runs Drone.Swarm cleanup and
disconnects members by default (same as Drone.Swarm.stop/1). Prefer
Drone.Swarm.stop/2 when you need disconnect: false.
Parameters
pid(pid()) — swarm process id
Returns
:ok{:error, :not_found}
Example
:ok = Drone.Swarm.Supervisor.stop_swarm(pid)