distribute/global

Types

A subject that can be registered globally and used with process groups. This type enforces codec usage for all operations, providing compile-time type safety for distributed messaging.

pub opaque type GlobalSubject(msg)

Values

pub fn decoder(
  global: GlobalSubject(msg),
) -> fn(BitArray) -> Result(msg, codec.DecodeError)

Get the decoder for this global subject.

pub fn encoder(
  global: GlobalSubject(msg),
) -> fn(msg) -> Result(BitArray, codec.EncodeError)

Get the encoder for this global subject.

pub fn from_pid(
  pid: process.Pid,
  encoder: fn(msg) -> Result(BitArray, codec.EncodeError),
  decoder: fn(BitArray) -> Result(msg, codec.DecodeError),
) -> GlobalSubject(msg)

Create a global subject from a Pid with required codec. Useful when you have a Pid from registry lookup.

pub fn from_subject(
  subject: process.Subject(BitArray),
  encoder: fn(msg) -> Result(BitArray, codec.EncodeError),
  decoder: fn(BitArray) -> Result(msg, codec.DecodeError),
) -> GlobalSubject(msg)

Create a global subject from an existing Subject(BitArray) with required codec. Useful when you already have a Subject (e.g., from start_global_receiver).

pub fn new(
  encoder: fn(msg) -> Result(BitArray, codec.EncodeError),
  decoder: fn(BitArray) -> Result(msg, codec.DecodeError),
) -> GlobalSubject(msg)

Create a new global subject for the current process with required codec. The encoder and decoder ensure all messages are type-safe.

pub fn owner(
  global: GlobalSubject(msg),
) -> Result(process.Pid, Nil)

Get the owner Pid of this global subject.

pub fn receive(
  global: GlobalSubject(msg),
  timeout_ms: Int,
) -> Result(msg, codec.DecodeError)

Receive a type-safe message from this global subject. The message is automatically decoded using the subject’s decoder.

pub fn send(
  global: GlobalSubject(msg),
  message: msg,
) -> Result(Nil, codec.EncodeError)

Send a type-safe message through this global subject. The message is automatically encoded using the subject’s encoder.

pub fn subject(
  global: GlobalSubject(msg),
) -> process.Subject(BitArray)

Get the underlying Subject(BitArray) for low-level operations. Prefer using send and receive methods for type-safe messaging.

Search Document