@@ -179,7 +179,6 @@ defmodule DynamicSupervisor do
179179 :max_restarts ,
180180 :max_seconds ,
181181 children: % { } ,
182- dynamic: 0 ,
183182 restarts: [ ]
184183 ]
185184
@@ -625,10 +624,10 @@ defmodule DynamicSupervisor do
625624 end
626625
627626 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
629628
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 )
632631 else
633632 { :reply , { :error , :max_children } , state }
634633 end
@@ -645,7 +644,7 @@ defmodule DynamicSupervisor do
645644 { :reply , reply , save_child ( pid , mfa , restart , shutdown , type , modules , state ) }
646645
647646 _ ->
648- { :reply , reply , update_in ( state . dynamic , & ( & 1 - 1 ) ) }
647+ { :reply , reply , state }
649648 end
650649 end
651650
@@ -664,14 +663,14 @@ defmodule DynamicSupervisor do
664663 end
665664 end
666665
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-
671666 defp save_child ( pid , mfa , restart , shutdown , type , modules , state ) do
667+ mfa = mfa_for_restart ( mfa , restart )
672668 put_in ( state . children [ pid ] , { mfa , restart , shutdown , type , modules } )
673669 end
674670
671+ defp mfa_for_restart ( { m , f , _ } , :temporary ) , do: { m , f , :undefined }
672+ defp mfa_for_restart ( mfa , _ ) , do: mfa
673+
675674 defp exit_reason ( :exit , reason , _ ) , do: reason
676675 defp exit_reason ( :error , reason , stack ) , do: { reason , stack }
677676 defp exit_reason ( :throw , value , stack ) , do: { { :nocatch , value } , stack }
@@ -888,9 +887,8 @@ defmodule DynamicSupervisor do
888887 { :ok , delete_child ( pid , state ) }
889888 end
890889
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 ) }
894892 end
895893
896894 defp restart_child ( pid , child , state ) do
0 commit comments