@@ -179,7 +179,6 @@ defmodule DynamicSupervisor do
179
179
:max_restarts ,
180
180
:max_seconds ,
181
181
children: % { } ,
182
- dynamic: 0 ,
183
182
restarts: [ ]
184
183
]
185
184
@@ -625,10 +624,10 @@ defmodule DynamicSupervisor do
625
624
end
626
625
627
626
def handle_call ( { :start_child , child } , _from , state ) do
628
- % { dynamic: dynamic , max_children: max_children } = state
627
+ % { children: children , max_children: max_children } = state
629
628
630
- if dynamic < max_children do
631
- handle_start_child ( child , % { state | dynamic: dynamic + 1 } )
629
+ if map_size ( children ) < max_children do
630
+ handle_start_child ( child , state )
632
631
else
633
632
{ :reply , { :error , :max_children } , state }
634
633
end
@@ -645,7 +644,7 @@ defmodule DynamicSupervisor do
645
644
{ :reply , reply , save_child ( pid , mfa , restart , shutdown , type , modules , state ) }
646
645
647
646
_ ->
648
- { :reply , reply , update_in ( state . dynamic , & ( & 1 - 1 ) ) }
647
+ { :reply , reply , state }
649
648
end
650
649
end
651
650
@@ -664,14 +663,14 @@ defmodule DynamicSupervisor do
664
663
end
665
664
end
666
665
667
- defp save_child ( pid , { m , f , _ } , :temporary , shutdown , type , modules , state ) do
668
- put_in ( state . children [ pid ] , { { m , f , :undefined } , :temporary , shutdown , type , modules } )
669
- end
670
-
671
666
defp save_child ( pid , mfa , restart , shutdown , type , modules , state ) do
667
+ mfa = mfa_for_restart ( mfa , restart )
672
668
put_in ( state . children [ pid ] , { mfa , restart , shutdown , type , modules } )
673
669
end
674
670
671
+ defp mfa_for_restart ( { m , f , _ } , :temporary ) , do: { m , f , :undefined }
672
+ defp mfa_for_restart ( mfa , _ ) , do: mfa
673
+
675
674
defp exit_reason ( :exit , reason , _ ) , do: reason
676
675
defp exit_reason ( :error , reason , stack ) , do: { reason , stack }
677
676
defp exit_reason ( :throw , value , stack ) , do: { { :nocatch , value } , stack }
@@ -888,9 +887,8 @@ defmodule DynamicSupervisor do
888
887
{ :ok , delete_child ( pid , state ) }
889
888
end
890
889
891
- defp delete_child ( pid , state ) do
892
- % { children: children , dynamic: dynamic } = state
893
- % { state | children: Map . delete ( children , pid ) , dynamic: dynamic - 1 }
890
+ defp delete_child ( pid , % { children: children } = state ) do
891
+ % { state | children: Map . delete ( children , pid ) }
894
892
end
895
893
896
894
defp restart_child ( pid , child , state ) do
0 commit comments