ExReg v0.1.0 ExReg View Source
This module defines the API for a simple and distributed process name
registry, using :pg2. 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
Link to this type
location()
View Source
location()
View Source
location() :: :local | :global
location() :: :local | :global
Location.
Link to this type
process_name() View Source
Process name.
Link to this section Functions
Link to this function
global(name)
View Source
global(name)
View Source
global(term()) :: {:via, ExReg, process_name()}
global(term()) :: {:via, ExReg, process_name()}
Generates a :via tuple for a global name.
Link to this function
local(name)
View Source
local(name)
View Source
local(term()) :: {:via, ExReg, process_name()}
local(term()) :: {:via, ExReg, process_name()}
Generates a :via tuple for a local name.
Link to this function
register_name(name, pid)
View Source
register_name(name, pid)
View Source
register_name(process_name(), pid()) :: :yes | :no
register_name(process_name(), pid()) :: :yes | :no
Registers name as an alias for a local pid globally.
Link to this function
send(name, message)
View Source
send(name, message)
View Source
send(process_name(), term()) :: pid() | no_return()
send(process_name(), term()) :: pid() | no_return()
Sends a message to the PID associated with name.
Link to this function
unregister_name(name)
View Source
unregister_name(name)
View Source
unregister_name(process_name()) :: :ok
unregister_name(process_name()) :: :ok
Unregisters a name.
Link to this function
whereis_name(name)
View Source
whereis_name(name)
View Source
whereis_name(process_name()) :: pid() | :undefined
whereis_name(process_name()) :: pid() | :undefined
Searches for the PID associated with the name.