Skip to content

Instantly share code, notes, and snippets.

@mattdeboard
Last active August 29, 2015 14:05
Show Gist options
  • Save mattdeboard/5d68daca4a0c439e12b3 to your computer and use it in GitHub Desktop.
Save mattdeboard/5d68daca4a0c439e12b3 to your computer and use it in GitHub Desktop.
defmodule Dexter do
use Application
@port 7400
def start(_ \\ nil, port \\ @port) do
import Supervisor.Spec, warn: false
children = [
worker(Reagent, [Dexter.Server, [port: port]])
]
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: :dexter_sup]
Supervisor.start_link(children, opts)
end
def handle_call(:children, from, state) do
[{_, child, _, _}] = Supervisor.which_children :dexter_sup
{:reply, child}
end
def get_server(pid) do
GenServer.call pid, :children
end
end
# iex:
{:ok, sv} = Dexter.start
Dexter.get_server sv
# ** (EXIT from #PID<0.234.0>) an exception was raised:
# ** (FunctionClauseError) no function clause matching in :supervisor.handle_call/3
# (stdlib) supervisor.erl:351: :supervisor.handle_call(:children, {#PID<0.234.0>, #Reference<0.0.0.1490>}, {:state, {:local, :dexter_sup}, :one_for_one, [{:child,
# #PID<0.239.0>, Reagent, {Reagent, :start_link, [Dexter.Server, [port: 7400]]}, :permanent, 5000, :worker, [Reagent]}], :undefined, 5, 5, [], Supervisor.Default, {:ok,
# {{:one_for_one, 5, 5}, [{Reagent, {Reagent, :start_link, [Dexter.Server, [port: 7400]]}, :permanent, 5000, :worker, [Reagent]}]}}})
# (stdlib) gen_server.erl:580: :gen_server.handle_msg/5
# (stdlib) proc_lib.erl:239: :proc_lib.init_p_do_apply/3
# Interactive Elixir (0.15.2-dev) - press Ctrl+C to exit (type h() ENTER for help)
# 18:53:53.317 [error] GenServer #PID<0.239.0> terminating
# Last message: {:EXIT, #PID<0.238.0>, :shutdown}
# State: %Reagent.Listener{acceptors: #HashSet<[#PID<0.249.0>, #PID<0.338.0>, #PID<0.304.0>, #PID<0.272.0>, #PID<0.295.0>, #PID<0.275.0>, #PID<0.328.0>, #PID<0.300.0>, #P
# ID<0.327.0>, #PID<0.283.0>, #PID<0.263.0>, #PID<0.313.0>, #PID<0.287.0>, #PID<0.332.0>, #PID<0.336.0>, #PID<0.314.0>, #PID<0.242.0>, #PID<0.267.0>, #PID<0.288.0>, #PID<
# 0.281.0>, #PID<0.297.0>, #PID<0.255.0>, #PID<0.294.0>, #PID<0.259.0>, #PID<0.284.0>, #PID<0.262.0>, #PID<0.318.0>, #PID<0.316.0>, #PID<0.290.0>, #PID<0.244.0>, #PID<0.2
# 80.0>, #PID<0.308.0>, #PID<0.298.0>, #PID<0.273.0>, #PID<0.310.0>, #PID<0.278.0>, #PID<0.296.0>, #PID<0.324.0>, #PID<0.265.0>, #PID<0.339.0>, #PID<0.274.0>, #PID<0.282.
# 0>, #PID<0.277.0>, #PID<0.307.0>, #PID<0.335.0>, #PID<0.323.0>, #PID<0.331.0>, #PID<0.240.0>, #PID<0.261.0>, ...]>, connections: #HashDict<[]>, env: %Exts.Dict{id: 2253
# 12, type: :set}, id: #PID<0.239.0>, module: Dexter.Server, options: [], port: 7400, secure: nil, socket: #Port<0.5825>, waiting: {[], []}}
# ** (exit) an exception was raised:
# ** (ErlangError) erlang error: :"module could not be loaded"
# :shutdown.socket()
# lib/reagent/listener.ex:140: Reagent.Listener.terminate/2
# (stdlib) gen_server.erl:721: :gen_server.terminate/6
# (stdlib) proc_lib.erl:239: :proc_lib.init_p_do_apply/3
# iex(1)>
# 18:53:53.319 [error] GenServer :dexter_sup terminating
# Last message: :children
# State: {:state, {:local, :dexter_sup}, :one_for_one, [{:child, #PID<0.239.0>, Reagent, {Reagent, :start_link, [Dexter.Server, [port: 7400]]}, :permanent, 5000, :worker,
# [Reagent]}], :undefined, 5, 5, [], Supervisor.Default, {:ok, {{:one_for_one, 5, 5}, [{Reagent, {Reagent, :start_link, [Dexter.Server, [port: 7400]]}, :permanent, 5000,
# :worker, [Reagent]}]}}}
# ** (exit) an exception was raised:
# ** (FunctionClauseError) no function clause matching in :supervisor.handle_call/3
# (stdlib) supervisor.erl:351: :supervisor.handle_call(:children, {#PID<0.234.0>, #Reference<0.0.0.1490>}, {:state, {:local, :dexter_sup}, :one_for_one, [{:child,
# #PID<0.239.0>, Reagent, {Reagent, :start_link, [Dexter.Server, [port: 7400]]}, :permanent, 5000, :worker, [Reagent]}], :undefined, 5, 5, [], Supervisor.Default, {:ok,
# {{:one_for_one, 5, 5}, [{Reagent, {Reagent, :start_link, [Dexter.Server, [port: 7400]]}, :permanent, 5000, :worker, [Reagent]}]}}})
# (stdlib) gen_server.erl:580: :gen_server.handle_msg/5
# (stdlib) proc_lib.erl:239: :proc_lib.init_p_do_apply/3
# nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment