Locker.Registry

This module provides a global process registry using locker Erlang library as the storage backend. It supports e.g., the GenServer‘s {:via, module, term} API.

Example

You can spawn a regular GenServer process that will be registered to locker using the GenServer API directly.

GenServer.start([], [name: {:via, Locker.Registry, "my_process"}])

Note that when using GenServer, you will need to refresh the registration using Locker.extend_lease/3. To avoid this, you should use Locker.Server instead of GenServer directly.

You can find out the process id of the named process using Locker.Registry.whereis_name.

Locker.Registry.whereis_name("my_process")
#=> {:ok, pid}

You can uregister the named process by calling Locker.Registry.unregister.

Locker.Registry.unregister("my_process")
Source

Summary

register_name(name, pid)

Registers the given pid to a name globally

send(name, msg)

Sends a message to the given name

unregister()

Unregisters the calling process

unregister_name(name)

Unregisters the given name

whereis_name(name)

Finds the process identifier for the given name

Functions

register_name(name, pid)

Specs:

  • register_name(any, pid) :: :yes | :no

Registers the given pid to a name globally.

Source
send(name, msg)

Specs:

  • send(any, any) :: :ok | {:badarg, {any, any}}

Sends a message to the given name.

Source
unregister()

Specs:

  • unregister :: nil

Unregisters the calling process.

Source
unregister_name(name)

Specs:

  • unregister_name(any) :: nil

Unregisters the given name.

Source
whereis_name(name)

Specs:

  • whereis_name(any) :: pid | :undefined

Finds the process identifier for the given name.

Source