iex(41)> {:ok, stack1} = Test.start_child{:ok, #PID<0.367.0>}iex(42)> Stack.pop(stack1)
23:03:56.303 [error] GenServer #PID<0.367.0> terminating** (FunctionClauseError) no function clause matching in Stack.handle_call/3 iex(42)> Stack.pop(stack1)** (exit) exited in: GenServer.call(#PID<0.367.0>, :pop, 5000) ** (EXIT) no process (elixir) lib/gen_server.ex:544: GenServer.call/3defmodule Test do use Application import Supervisor.Spec, warn: false
def start(_type, _args) do
children = [ worker(Stack, []) ]
opts = [strategy: :simple_one_for_one, name: Test.Supervisor] Supervisor.start_link(children, opts) end
def start_child do Supervisor.start_child(Test.Supervisor, []) endend
defmodule Stack do use GenServer
def start_link do GenServer.start_link(__MODULE__, [], []) end
def pop(pid) do GenServer.call(pid, :pop) end
def handle_call(:pop, _from, [h|t]) do {:reply, h, t} end
endchildren = [ worker(Stack, [], restart: :transient),]Take a look through http://elixir-lang.org/docs/v1.0/elixir/Supervisor.Spec.html for further info.
defmodule Test douse Applicationimport Supervisor.Spec, warn: falsedef start(_type, _args) dochildren = [worker(Stack, [])]opts = [strategy: :simple_one_for_one, name: Test.Supervisor]Supervisor.start_link(children, opts)enddef start_child doSupervisor.start_child(Test.Supervisor, [])endenddefmodule Stack douse GenServer
def start_link(name) doGenServer.start_link(__MODULE__, [], name: name)
enddef pop(pid) doGenServer.call(pid, :pop)enddef handle_call(:pop, _from, [h|t]) do{:reply, h, t}endend
iex(41)> {:ok, _} = Test.start_child(:foo){:ok, #PID<0.367.0>}iex(42)> Stack.pop(:foo)iex(42)> Stack.pop(:foo)
--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/0acd535c-1e4a-4197-bc5c-7e7cc316f08f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
These are options for the Supervisor.start_link function call rather, my bad. If you were building supervisors a different way it would be a supervise call.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/3653c19e-5165-48ae-aefc-c2be5bcc926b%40googlegroups.com.