elixir-lang / gen_stage

Producer and consumer actors with back-pressure for Elixir
http://hexdocs.pm/gen_stage
1.48k stars 192 forks source link

fix(ConsumerSupervisor): allow map-style child specs #268

Closed paulswartz closed 3 years ago

paulswartz commented 3 years ago

Supervisor.Spec.spec() is the older tuple-style child spec. ConsumerSupervisor.init/2 support the newer map-style child specs, but the type did not not reflect that. That resulted in Dialyzer errors like this:

example.ex:8:no_return
Function start_link/1 has no local return.
________________________________________________________________________________
example.ex:24:call
The function call will not succeed.

ConsumerSupervisor.start_link(
  _children :: [
    %{:id => _, :restart => :temporary, :start => {_, :start_link, [Keyword.t(), ...]}},
    ...
  ],
  _supervisor_opts :: [{atom(), _}, ...]
)

breaks the contract
Contract head:
([Supervisor.Spec.spec()], [option()]) :: Supervisor.on_start()

Contract head:
(module(), any()) :: Supervisor.on_start()

This updates the spec to show that start_link/2 can also accept a map.

josevalim commented 3 years ago

:green_heart: :blue_heart: :purple_heart: :yellow_heart: :heart: