ExReg (ExReg v1.0.0) View Source
This module defines the API for a simple and distributed process name
registry, using :pg
. The following features are supported:
- Accepts any term as process names.
- Works distributedly.
- Supports registering processes with the same name as long as they are in different nodes.
iex>pid = self()
#PID<0.42.0>
iex> ExReg.register_name(:foo, pid)
:yes
iex> ExReg.whereis_name(:foo)
#PID<0.42.0>
iex> ExReg.send(:foo, "bar")
iex> flush()
"bar"
:ok
iex> ExReg.unregister_name(:foo)
:ok
iex> ExReg.send(:foo, "hey")
** (ArgumentError) Cannot send "hey" to :foo
Link to this section Summary
Functions
Generates a :via
tuple for a global name
.
Generates a :via
tuple for a local name
.
Registers name
as an alias for a local pid
globally.
Sends a message
to the PID associated with name
.
Unregisters a name
.
Searches for the PID associated with the name
.
Link to this section Types
Specs
location() :: :local | :global
Location.
Specs
Process name.
Link to this section Functions
Specs
global(term()) :: {:via, ExReg, process_name()}
Generates a :via
tuple for a global name
.
Specs
local(term()) :: {:via, ExReg, process_name()}
Generates a :via
tuple for a local name
.
Specs
register_name(process_name(), pid()) :: :yes | :no
Registers name
as an alias for a local pid
globally.
Specs
send(process_name(), term()) :: pid() | no_return()
Sends a message
to the PID associated with name
.
Specs
unregister_name(process_name()) :: :ok
Unregisters a name
.
Specs
whereis_name(process_name()) :: pid() | :undefined
Searches for the PID associated with the name
.