Skip to content

Instantly share code, notes, and snippets.

@alvises
Created September 15, 2016 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvises/7f5329ac9bfe0c0803de4a0c7d97b91e to your computer and use it in GitHub Desktop.
Save alvises/7f5329ac9bfe0c0803de4a0c7d97b91e to your computer and use it in GitHub Desktop.
supervised genstage, producer, producer_consumer, consumer
{:ok, p} = Producer.start_link
workers_num = 20
workers = Enum.map(1..workers_num, fn (n)->
worker(ProducerConsumer, [worker_name(n)], id: n)
end)
worker_names = Enum.map 1..8, &worker_name/1
#consumer subscribes to the producer names passed
consumers = [worker(Consumer, [worker_names])]
children = workers ++ consumers
Supervisor.start_link children, strategy: :rest_for_one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment