defmodule SomeModule do | |
def start(host, options) do | |
# We are assuming SomeSup has been already started somewhere | |
# (ideally in a supervision tree). | |
{:ok, child_pid} = SomeSup.attach_to(SomeSup, host, options) | |
end | |
end | |
defmodule SomeSup do | |
use Supervisor | |
def attach_to sup, host, options do | |
Supervisor.start_child(sup, [host, options]) | |
end | |
def start_link do | |
Supervisor.start_link(__MODULE__, [], name: __MODULE__) | |
end | |
def init [] do | |
supervise([worker(SomeWorker, [], restart: :temporary)], strategy: :simple_one_for_one) | |
end | |
end | |
defmodule SomeWorker do | |
use GenServer | |
alias :gproc, as: GProc | |
def start_link host, options do | |
GenServer.start_link(__MODULE__, [host, options], name: {:via, GProc, {:n, :l, :conv_id}}) | |
end | |
def init [host, options] do | |
#Let GProc know that this is a conversation | |
GProc.reg({:p, :l, :conversation}) | |
{:ok, []} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment