While working with the DynamicSupervisor library, it is not clear to me whether I can as supervisor a supervisor create by Supervisor in any of the DynamicSupervisor functions and vice-versa.
The specs in DynamicSupervisor mention that supervisor is a t:Supervisor.supervisor/0, but I have the feeling we should have a t:DynamicSupervisor.supervisor/0 of its own, as they donāt interoperate.
Error message does not help as it returns {:error, {:invalid_child_spec, child_spec}} while the spec is valid, but the issue stems from the interop issue.
If it existed, a DynamicSupervisor.supervisor() type would have the same values as Supervisor.supervisor() - the possible values are ways to identify an supervisor process, not specific details about the kind of process.
To use a telecom analogy, the type says āthis is what patterns of numbers you can dial to reach a remote phoneā but doesnāt specify who answers.
Many of the functions in the two modules are nearly identical, but handle arguments a little differently - for instance, start_child:
vs
Both ultimately result in a GenServer.call with a message shaped like {:start_child, child_spec}.
Yes, but internally, the child spec for DynamicSupervisor is a five-element tuple, and for Supervisor is like the old erlang child spec, with 6 elements IIRC.
The error is cryptic, it says ā:invalid_child_specā and if you call the same function with the same child spec but your suppervisor goes to the local supervisor the the function works fine, since the chld spec was valid.
Having a new type is a way to document that DynamicSupervisor functions expect a DynamicSupervisor and not a regular Supervisor.