Created
October 9, 2015 01:23
-
-
Save bbhoss/b988d519345e5c3054cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyServer do | |
use GenServer | |
def init(_args) do | |
:gproc.reg({:p, :l, :my_little_server}) | |
{:ok, []} | |
end | |
def handle_info(msg, state) do | |
IO.inspect "Got #{inspect msg} in process #{inspect self()}" | |
{:noreply, state} | |
end | |
end | |
# | |
# iex> {:ok, pid1} = GenServer.start_link(MyServer, [], []) | |
# iex> {:ok, pid2} = GenServer.start_link(MyServer, [], []) | |
# iex> :gproc.send({:p, :l, :my_little_server}, :hello_world) | |
# "Got :hello_world in process #PID<0.6726.0>" | |
# "Got :hello_world in process #PID<0.6728.0>" | |
# :hello_world |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Preston, this looks like a really good pattern. How could I use it if I wanted to initiate N subscribers (
GenServer.start_link
etc) that have one supervisor? I've tried to do it myself, but with no luck! Thanks