March Docs

GlobalPid

GlobalPid: a serializable, cluster-wide process handle (P1 L4 prerequisite).

Location-transparent send/cast/call need a process identity that survives the wire. A global Pid is {NodeId, local_pid, creation}: the owning node, the node-local scheduler pid (the runtime's integer PID), and a creation counter that distinguishes a restarted node's reused local pids from the originals (so a stale Pid from before a restart is detectably stale). It round-trips through MessagePack to ride inside a NetFrame.

Types

typePidPid = { node_id : String, local_pid : Int, creation : Int }#

Functions

fndecodedecode(bytes : List(Int)) : Result(Pid, String)#

Decode bytes produced by encode. Returns Err for invalid MessagePack (the decoder's message) or a malformed pid.

fnencodeencode(p : Pid) : List(Int) do Msgpack.encode(to_value(p)) end#

The pid's MessagePack wire bytes (Msgpack.encode(to_value(p))).

Examples

GlobalPid.decode(GlobalPid.encode(GlobalPid.make("n1", 7, 1)))
-- Ok(GlobalPid.make("n1", 7, 1))
fneqeq(a : Pid, b : Pid) : Bool#

Whether [a] and [b] name the same process: same node, same local pid AND same creation, so a pid from before a node restart never equals one from after it.

Examples

march> GlobalPid.eq(GlobalPid.make("n1", 7, 1), GlobalPid.make("n1", 7, 1))
true
march> GlobalPid.eq(GlobalPid.make("n1", 7, 1), GlobalPid.make("n1", 7, 2))
false
fnmakemake(node_id : String, local_pid : Int, creation : Int) : Pid#

A global pid for local pid [local_pid] on node [node_id] in that node's [creation].

Examples

march> let gp = GlobalPid.make("n1", 7, 2)
march> gp.local_pid
7
march> let gp = GlobalPid.make("n1", 7, 2)
march> gp.node_id
"n1"
fnof_valueof_value(v) : Result(Pid, String)#

Read a pid back from a MessagePack value produced by to_value. Returns Err("GlobalPid: malformed pid") for anything that is not exactly a 3-element array of (Str, Int, Int).

fnto_valueto_value(p : Pid)#

The pid as a MessagePack value, the array [node_id, local_pid, creation], for nesting inside a larger record. (The return type is left to inference: the Msgpack Value type collides in the global namespace.)