Skip to content

Commit

Permalink
Initialize chat rooms dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
brianstorti committed Mar 3, 2016
1 parent c728238 commit c3675e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/chat/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions lib/chat/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ 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
children = [
worker(Chat.Server, [])
]

supervise(children, strategy: :one_for_one)
supervise(children, strategy: :simple_one_for_one)
end
end

0 comments on commit c3675e1

Please sign in to comment.