From c3675e16125c83bccac0c3456a42dd30a28f162b Mon Sep 17 00:00:00 2001 From: Brian Thomas Storti Date: Thu, 3 Mar 2016 22:25:48 +0100 Subject: [PATCH] Initialize chat rooms dynamically --- lib/chat/server.ex | 2 +- lib/chat/supervisor.ex | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/chat/server.ex b/lib/chat/server.ex index 8cee829..b073192 100644 --- a/lib/chat/server.ex +++ b/lib/chat/server.ex @@ -3,7 +3,7 @@ defmodule Chat.Server do # API - def start_link do + def start_link(name) do GenServer.start_link(__MODULE__, [], name: :chat_room) end diff --git a/lib/chat/supervisor.ex b/lib/chat/supervisor.ex index 9d982ed..92afb0f 100644 --- a/lib/chat/supervisor.ex +++ b/lib/chat/supervisor.ex @@ -2,7 +2,11 @@ defmodule Chat.Supervisor do use Supervisor def start_link do - Supervisor.start_link(__MODULE__, []) + Supervisor.start_link(__MODULE__, [], name: :chat_supervisor) + end + + def start_room(name) do + Supervisor.start_child(:chat_supervisor, [name]) end def init(_) do @@ -10,6 +14,6 @@ defmodule Chat.Supervisor do worker(Chat.Server, []) ] - supervise(children, strategy: :one_for_one) + supervise(children, strategy: :simple_one_for_one) end end