Skip to content

Instantly share code, notes, and snippets.

@bbhoss
Created October 9, 2015 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbhoss/b988d519345e5c3054cd to your computer and use it in GitHub Desktop.
Save bbhoss/b988d519345e5c3054cd to your computer and use it in GitHub Desktop.
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
@scra88le
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment