distribute/registry
Types
Errors from registry operations.
pub type RegisterError {
AlreadyExists
InvalidProcess
InvalidArgument(String)
NetworkError(String)
RegistrationFailed(String)
}
Constructors
-
AlreadyExistsName is already registered by another process.
-
InvalidProcessProcess is not alive or invalid.
-
InvalidArgument(String)Name is empty, too long, or contains invalid characters.
-
NetworkError(String)Network partition or connectivity issue.
-
RegistrationFailed(String)Generic registration failure.
Values
pub fn is_registered(name: String) -> Bool
Check whether a name is currently registered.
pub fn lookup(
tn: TypedName(msg),
) -> Result(global.GlobalSubject(msg), Nil)
Look up a globally registered GlobalSubject by TypedName.
Reconstructs the Subject with a deterministic tag derived from the name.
pub fn lookup_with_timeout(
tn: TypedName(msg),
timeout_ms: Int,
poll_interval_ms: Int,
) -> Result(global.GlobalSubject(msg), Nil)
Look up a GlobalSubject with polling and timeout.
Retries the lookup every poll_interval_ms until found or
timeout_ms elapses.
pub fn named(name: String, c: codec.Codec(msg)) -> TypedName(msg)
Same as typed_name but takes a bundled Codec.
let counter = registry.named("counter", codec.int())
pub fn pool_member(
base: TypedName(msg),
index: Int,
) -> TypedName(msg)
Create a TypedName for a pool member.
Given a base TypedName with name "worker" and index 2,
returns a TypedName with name "worker_2" and the same codecs.
pub fn register(
name: String,
pid: process.Pid,
) -> Result(Nil, RegisterError)
Register a PID under a global name.
pub fn register_global(
tn: TypedName(msg),
global_subject: global.GlobalSubject(msg),
) -> Result(Nil, RegisterError)
Register a GlobalSubject under a typed name.
The msg type parameter on TypedName(msg) and GlobalSubject(msg)
must match — the compiler enforces this.
pub fn register_typed(
name: String,
subject: process.Subject(msg),
) -> Result(Nil, RegisterError)
Register a Subject’s owner PID under a global name.
pub fn typed_name(
name: String,
encoder: fn(msg) -> Result(BitArray, codec.EncodeError),
decoder: fn(BitArray) -> Result(msg, codec.DecodeError),
) -> TypedName(msg)
Create a typed name.
Share this value between registration and lookup so the compiler can check that both sides use the same message type.
pub fn typed_name_decoder(
tn: TypedName(msg),
) -> fn(BitArray) -> Result(msg, codec.DecodeError)
Get the decoder from a TypedName.
pub fn typed_name_encoder(
tn: TypedName(msg),
) -> fn(msg) -> Result(BitArray, codec.EncodeError)
Get the encoder from a TypedName.
pub fn typed_name_to_string(tn: TypedName(msg)) -> String
Get the name string from a TypedName.
pub fn unregister(name: String) -> Result(Nil, RegisterError)
Unregister a global name.
Always succeeds — unregistering a non-existent name is a no-op.
pub fn whereis(name: String) -> Result(process.Pid, Nil)
Look up a globally registered PID by name.