Concurrent Data Processing in Elixir: Page(72)

Spining multiple PageConsumer using the book provided code, raise an error

   children = [
      PageProducer,
      Supervisor.child_spec(PageConsumer, id: :consumer_a),
      Supervisor.child_spec(PageConsumer, id: :consumer_b)
    ]

But I open an issue on Github Elixir repo, and the fix proposed by Jose Valim is

# in the consumer PageConsumer module
  def start_link(opts) do
    GenStage.start_link(__MODULE__, [], name: opts[:name])
  end

# application.ex
children = [
      {Scrapper.PageProducer, []},
      Supervisor.child_spec({Scrapper.PageConsumer, [name: :consumer_a]}, id: :consumer_a),
      Supervisor.child_spec({Scrapper.PageConsumer, [name: :consumer_b]}, id: :consumer_b)
    ]

1 Like