Bier.Registry (bier v0.1.0)

Copy Markdown View Source

Local key-value process storage for Bier instances

Summary

Functions

Retrieves the configuration for a Bier instance

Retrieves the configuration for a Bier instance, or :error when no such instance is registered

Returns the names of the Bier instances currently registered (live supervisors)

Returns a via tuple useful for processes name registration

Returns the process identifier (pid) of a supervised Bier process

Types

key()

@type key() :: Bier.name() | {Bier.name(), role()}

role()

@type role() :: term()

value()

@type value() :: term()

Functions

config(name)

@spec config(Bier.name()) :: Bier.Config.t()

Retrieves the configuration for a Bier instance

Examples

Get the default Bier instance configuration:

Bier.Registry.config(Bier)

fetch_config(name)

@spec fetch_config(Bier.name()) :: {:ok, Bier.Config.t()} | :error

Retrieves the configuration for a Bier instance, or :error when no such instance is registered

Same lookup as config/1, for callers that must tolerate an unregistered name (e.g. an error raised before the request reached a live instance) instead of raising.

Examples

Bier.Registry.fetch_config(Bier)
#=> {:ok, %Bier.Config{}}

instance_names()

@spec instance_names() :: [Bier.name()]

Returns the names of the Bier instances currently registered (live supervisors)

Instance supervisors register under the bare (atom) name; instance-scoped processes under {name, role} tuples — only the bare names are returned.

Examples

Bier.Registry.instance_names()
#=> [Bier]

via(name, role \\ nil, value \\ nil)

@spec via(Bier.name(), role(), value()) :: {:via, Registry, {Bier.Registry, key()}}

Returns a via tuple useful for processes name registration

Examples

To retrieve a suitable via tuple for a Bier supervisor:

Bier.Registry.via(Bier)

In case you want to use the via tuple to store process metadata you can proceed as follows:

Bier.Registry.via(Bier, nil, config)

whereis(name, role \\ nil)

@spec whereis(Bier.name(), role()) :: pid() | nil

Returns the process identifier (pid) of a supervised Bier process

If the given process can't be found, the returned value is nil.

Examples

Retrieves the Bier supervisor's pid:

Bier.Registry.whereis(Bier)

Get a supervised module's pid:

Bier.Registry.whereis(Bier, Postgrex)