Lockstep.Process (Lockstep v0.1.0)

Copy Markdown View Source

Controller-aware wrappers for Process.whereis/1, Process.register/2, Process.unregister/1, and Process.registered/0.

These rewrite the per-name registry to be per-node rather than BEAM-global, so atom names like :counter can refer to different pids on different simulated cluster nodes. Without this, every name lives in a single BEAM-wide table and you get spurious :already_registered collisions when the same registered name legitimately exists on multiple nodes.

Falls through to BEAM's vanilla Process.* calls when no Lockstep controller is in scope.

Rewriter integration

Lockstep.Rewriter rewrites bare Process.whereis/1, Process.register/2, Process.unregister/1, and Process.registered/0 to the corresponding Lockstep.Process.* calls.

Summary

Functions

Register pid_or_name under name on the registered process's notional node. Mirrors Process.register/2.

List atom names registered on the calling process's node. Mirrors Process.registered/0.

Set a debug label on the current process. Mirrors OTP 27+'s set_label/1 from the Process module but works on older OTPs by no-op'ing -- the label is purely cosmetic for :observer / debug tooling, so it's safe to ignore.

Unregister name on the calling process's node. Mirrors Process.unregister/1.

Look up a process registered under name on the calling process's notional cluster node. Returns the pid or nil. Mirrors Process.whereis/1.

Functions

register(pid_or_name, name)

@spec register(pid() | atom(), atom()) :: true

Register pid_or_name under name on the registered process's notional node. Mirrors Process.register/2.

Returns true on success. Raises ArgumentError if the name is already registered on that node, or if the pid is already registered under another name.

registered()

@spec registered() :: [atom()]

List atom names registered on the calling process's node. Mirrors Process.registered/0.

set_label(label)

@spec set_label(any()) :: :ok

Set a debug label on the current process. Mirrors OTP 27+'s set_label/1 from the Process module but works on older OTPs by no-op'ing -- the label is purely cosmetic for :observer / debug tooling, so it's safe to ignore.

unregister(name)

@spec unregister(atom()) :: true

Unregister name on the calling process's node. Mirrors Process.unregister/1.

Returns true on success. Raises ArgumentError if no such name.

whereis(name)

@spec whereis(atom()) :: pid() | nil

Look up a process registered under name on the calling process's notional cluster node. Returns the pid or nil. Mirrors Process.whereis/1.