Skip to content

Instantly share code, notes, and snippets.

@neektza
Created February 3, 2016 18:18
Show Gist options
  • Save neektza/572891715e978ee9d7b8 to your computer and use it in GitHub Desktop.
Save neektza/572891715e978ee9d7b8 to your computer and use it in GitHub Desktop.
Confused?
defmodule MessageSpammer.Connector do
use Supervisor
def start_link do
Supervisor.start_link(__MODULE__, [])
end
def init(_) do
IO.puts "Starting Connector"
clients = spawn_clients([], 100)
IO.inspect clients
spammer = worker(MessageSpammer.Spammer, [{:interval, 1, :pids, clients}], restart: :temporary)
Supervisor.start_link([spammer], [strategy: :one_for_one, name: MessageSpammer.Supervisor]) # WORKS
supervise([spammer], strategy: :simple_one_for_one) # DOESNT WORK
end
def spawn_clients(pids, cnt) do
l = length(pids) + 1
if l < cnt do
{ :ok, client_pid } = MessageSpammer.Client.start_link(%{})
MessageSpammer.Client.connect(client_pid, [client_id: "client-#{l}", host: "localhost", port: 1883])
spawn_clients(pids ++ [client_pid], cnt)
else
pids
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment