From 27f0b18738ba36a9a2850e8d977f6212332bb5d3 Mon Sep 17 00:00:00 2001 From: Adam Millerchip Date: Tue, 25 Feb 2025 15:39:49 +0900 Subject: [PATCH] Add more docs about :already_started for DynamicSupervisor (#14298) --- lib/elixir/lib/dynamic_supervisor.ex | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/elixir/lib/dynamic_supervisor.ex b/lib/elixir/lib/dynamic_supervisor.ex index 72f5167898..d910c684ad 100644 --- a/lib/elixir/lib/dynamic_supervisor.ex +++ b/lib/elixir/lib/dynamic_supervisor.ex @@ -230,7 +230,14 @@ defmodule DynamicSupervisor do @typedoc "Supported strategies" @type strategy :: :one_for_one - @typedoc "Return values of `start_child` functions" + @typedoc """ + Return values of `start_child` functions. + + Unlike `Supervisor`, this module ignores the child spec ids, so + `{:error, {:already_started, pid}}` is not returned for child specs given with the same id. + `{:error, {:already_started, pid}}` is returned however if a duplicate name is used when using + [name registration](`m:GenServer#module-name-registration`). + """ @type on_start_child :: {:ok, pid} | {:ok, pid, info :: term} @@ -400,11 +407,13 @@ defmodule DynamicSupervisor do @doc """ Dynamically adds a child specification to `supervisor` and starts that child. - `child_spec` should be a valid child specification as detailed in the - "Child specification" section of the documentation for `Supervisor`. The child - process will be started as defined in the child specification. Note that while + `child_spec` should be a valid [child specification](`m:Supervisor#module-child-specification`). + The child process will be started as defined in the child specification. Note that while the `:id` field is still required in the spec, the value is ignored and - therefore does not need to be unique. + therefore does not need to be unique. Unlike `Supervisor`, this module does not + return `{:error, {:already_started, pid}}` for child specs given with the same id. + `{:error, {:already_started, pid}}` is returned however if a duplicate name is + used when using [name registration](`m:GenServer#module-name-registration`). If the child process start function returns `{:ok, child}` or `{:ok, child, info}`, then child specification and PID are added to the supervisor and