distribute/global
Types
pub type CallError {
CallTimeout
CallEncodeFailed(codec.EncodeError)
CallDecodeFailed(codec.DecodeError)
}
Constructors
-
CallTimeout -
CallEncodeFailed(codec.EncodeError) -
CallDecodeFailed(codec.DecodeError)
A subject with a codec, usable across nodes.
pub opaque type GlobalSubject(msg)
Values
pub fn call(
target: GlobalSubject(req),
make_request: fn(process.Subject(BitArray)) -> req,
response_decoder: fn(BitArray) -> Result(
resp,
codec.DecodeError,
),
timeout_ms: Int,
) -> Result(resp, CallError)
Synchronous request/response. Creates a temporary subject, sends
the request (built by make_request), waits for the reply.
The handler must call reply with the same subject.
pub fn call_error_to_string(error: CallError) -> String
pub fn decoder(
global: GlobalSubject(msg),
) -> fn(BitArray) -> Result(msg, codec.DecodeError)
pub fn encoder(
global: GlobalSubject(msg),
) -> fn(msg) -> Result(BitArray, codec.EncodeError)
pub fn from_name(
name: String,
pid: process.Pid,
encoder: fn(msg) -> Result(BitArray, codec.EncodeError),
decoder: fn(BitArray) -> Result(msg, codec.DecodeError),
) -> GlobalSubject(msg)
Subject from a name and PID. The name is the tag, so any node that knows the name can reconstruct the same Subject.
pub fn from_pid(
pid: process.Pid,
encoder: fn(msg) -> Result(BitArray, codec.EncodeError),
decoder: fn(BitArray) -> Result(msg, codec.DecodeError),
) -> GlobalSubject(msg)
Subject from a remote PID. Nil tag, send-only — you can’t receive on it from the calling process.
pub fn from_subject(
subject: process.Subject(BitArray),
encoder: fn(msg) -> Result(BitArray, codec.EncodeError),
decoder: fn(BitArray) -> Result(msg, codec.DecodeError),
) -> GlobalSubject(msg)
Wrap an existing Subject(BitArray), keeping its tag.
pub fn new(
encoder: fn(msg) -> Result(BitArray, codec.EncodeError),
decoder: fn(BitArray) -> Result(msg, codec.DecodeError),
) -> GlobalSubject(msg)
New subject owned by the current process, with a unique tag.
pub fn owner(
global: GlobalSubject(msg),
) -> Result(process.Pid, Nil)
pub fn receive(
global: GlobalSubject(msg),
timeout_ms: Int,
) -> Result(msg, codec.DecodeError)
Receive and decode a message. Only works on subjects you own.
pub fn reply(
reply_to: process.Subject(BitArray),
response: resp,
encoder: fn(resp) -> Result(BitArray, codec.EncodeError),
) -> Result(Nil, codec.EncodeError)
Send a response through a reply subject. Used by the handler
to answer a call.
pub fn send(
global: GlobalSubject(msg),
message: msg,
) -> Result(Nil, codec.EncodeError)
Encode and send a message.
pub fn subject(
global: GlobalSubject(msg),
) -> process.Subject(BitArray)