aboutsummaryrefslogtreecommitdiff
path: root/lib/octochat/server_supervisor.ex
diff options
context:
space:
mode:
authorkballou <kballou@devnulllabs.io>2016-10-31 03:23:48 -0600
committerkballou <kballou@devnulllabs.io>2016-10-31 04:03:09 -0600
commit3bcdc01d8de970905bf923e5cddc7a567d12de0e (patch)
tree740f36c7e5e78916c21be306e92d8e2f7c36dcad /lib/octochat/server_supervisor.ex
parent6ce4db4dfa1a5a137a83e4f7f56340a763d23fee (diff)
downloadoctochat-3bcdc01d8de970905bf923e5cddc7a567d12de0e.tar.gz
octochat-3bcdc01d8de970905bf923e5cddc7a567d12de0e.tar.xz
Level up our echo serverv0.3.0
This should enable upgrade process to retain connections * Replace our simple task supervisor with a custom `simple_one_for_one` supervisor * Upgrade our echo server to use a `GenServer` behaviour
Diffstat (limited to 'lib/octochat/server_supervisor.ex')
-rw-r--r--lib/octochat/server_supervisor.ex24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/octochat/server_supervisor.ex b/lib/octochat/server_supervisor.ex
new file mode 100644
index 0000000..d412ca5
--- /dev/null
+++ b/lib/octochat/server_supervisor.ex
@@ -0,0 +1,24 @@
+defmodule Octochat.ServerSupervisor do
+ @moduledoc """
+ Simple One-for-One Supervisor for socket connections
+ """
+
+ use Supervisor
+
+ def start_link() do
+ Supervisor.start_link(__MODULE__, :ok, name: __MODULE__)
+ end
+
+ def init(:ok) do
+ children = [
+ worker(Octochat.Echo, [], restart: :temporary)
+ ]
+
+ supervise(children, strategy: :simple_one_for_one)
+ end
+
+ def start_server(socket) do
+ Supervisor.start_child(__MODULE__, [socket])
+ end
+
+end