Skip to content

Commit 5d7ee90

Browse files
author
José Valim
committed
Implement child_spec/1 for DynamicSupervisor
1 parent 66cf08e commit 5d7ee90

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/elixir/lib/dynamic_supervisor.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ defmodule DynamicSupervisor do
165165
restarts: []
166166
]
167167

168+
@doc false
169+
def child_spec(arg) do
170+
%{
171+
id: DynamicSupervisor,
172+
start: {DynamicSupervisor, :start_link, [arg]},
173+
type: :supervisor
174+
}
175+
end
176+
168177
@doc false
169178
defmacro __using__(opts) do
170179
quote location: :keep, bind_quoted: [opts: opts] do

lib/elixir/test/elixir/dynamic_supervisor_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ defmodule DynamicSupervisorTest do
99
def init(args), do: args
1010
end
1111

12+
test "can be supervised directly" do
13+
children = [{DynamicSupervisor, strategy: :one_for_one, name: :dyn_sup_spec_test}]
14+
assert {:ok, _} = Supervisor.start_link(children, strategy: :one_for_one)
15+
assert DynamicSupervisor.which_children(:dyn_sup_spec_test) == []
16+
end
17+
1218
describe "use/2" do
1319
test "generates child_spec/1" do
1420
assert Simple.child_spec([:hello]) == %{

0 commit comments

Comments
 (0)