Skip to main content

Module samples

Module samples 

Source
Expand description

Built-in demo chunks assembled with crate::Program.

Use these as runnable specs of the messaging contract (and as regression tests). Prefer copying a sample over inventing hop register layouts from scratch.

SampleShows
add_forty_twoScalar VM path (no natives)
ping_pongCap spawn + Atomic Hop round-trip
atomic_request_replyTagged REQ/REP + correlated receive
atomic_actorsServer loop + two Ask clients + minted request_id
cap_in_payloadCap in hop payload is reissued to the recipient
cap_in_listCap nested in a List is reissued the same way
selective_receiveReceiveMatch FIFO skip
selective_receive_timeoutBEAM after: ReceiveMatchImmTimeout → Unit
selective_receive_afterafter still skips junk and hits the tag
process_aliveIsAlive (BEAM is_process_alive/1)
process_dictprocess dictionary put / get / erase
receive_match_eqterm equality: tag + Int payload
exit_signalBEAM exit/2 → DOWN with Fault
supervised_treebytecode StartChild under a host supervisor
receive_match_kindReceiveMatchKind by payload wire-tag
ask_replyAsk RPC hop
ask_timeout_expiresAskTimeout writes Unit when the server stays silent
ask_target_exitsAsk dest is TAG_SYS_EXIT when the server dies first
server_loopBEAM-style receive → handle → reply loop
named_serviceBytecode register_name / whereis (Cap, not FlowId)
forged_sender_send / forged_sender_askS1: forged make_msg sender dies
boomImmediate trap (supervisor demos)
monitor_downMonitor → crate::TAG_SYS_DOWN on child exit
waiting_sendWAITING_SEND: second hop parks until the first is received

Lifecycle regression tests in this module (not demo samples) also cover trap_exit / SetTrapExit and linked TAG_SYS_EXIT hops.

Hop samples require crate::std_native_table.

Constants§

TAG_DONE
Client → parent completion hop in atomic_actors (not an RPC reply).
TAG_JUNK
Decoy hop for selective_receive — must be skipped by ReceiveMatch.
TAG_PING
TAG_PONG
TAG_READY
Readiness handshake (e.g. SetTrapExit before link).
TAG_REP
TAG_REQ
Protocol tags for Atomic Hop samples.

Functions§

add_forty_two
41 + 1; return — the 60-second sanity chunk.
ask_reply
Atomic request/reply via Ask (RPC hop).
ask_target_exits
Server takes the request and exits; client Ask must not hang.
ask_timeout_expires
AskTimeout against a server that never replies → Unit.
atomic_actors
Canonical Atomic Hop actor demo: one server loop, two clients, each doing N Asks with minted request_ids. Each client asserts that the reply echoes the request’s request_id before accumulating. Main waits for both DONE hops and returns the sum (2 * 36 = 72).
atomic_request_reply
Atomic request-reply with crate::Value::Message (one envelope per hop).
boom
Immediate Trap — used to show crate::Supervisor restart.
cap_in_list
Same grant as cap_in_payload, with the cap nested in a list.
cap_in_payload
Server receives a Cap in the payload and sends 42 back through it. Exercises hop-time reissue (holder becomes the recipient).
exit_signal
BEAM exit/2: child parked on receive dies with Fault; monitor payload is 3.
forged_sender_ask
Same security property as forged_sender_send, via Ask.
forged_sender_send
Security regression: forged make_msg sender must not survive Send.
monitor_down
Child sleeps then exits; parent monitors and returns the DOWN reason (0 = normal).
named_service
Server publishes "svc"; client loops whereis until it gets a SEND Cap (not ASK — use Send + Receive, not Ask). Returns 42 (41 + 1). Discovery never exposes a raw FlowId.
ping_pong
Two flows, one Atomic Hop round-trip: main sends a Message to pong, pong replies with payload+1 via msg_reply_cap, main returns that payload (2).
process_alive
BEAM is_process_alive/1: a parked child is live; after DOWN, its Cap is not.
process_dict
Process dictionary (put / get / erase): store 41, add 1 in a register, erase still yields the stored 41. Returns 42 + 41 = 83.
receive_match_eq
Term equality receive: skip a TAG_REQ whose payload is 0, take 41.
receive_match_kind
Selective receive by payload wire-tag (ReceiveMatchKind): skip hops whose payload is not Int (tag 2), then reply with that payload.
selective_receive
Selective Atomic Hop: server waits for TAG_REQ while a TAG_JUNK hop sits ahead in the mailbox (FIFO skip, not drop).
selective_receive_after
Selective receive + after: junk stays queued, TAG_REQ arrives in time.
selective_receive_timeout
BEAM receive … after: nobody sends TAG_REQ, so the wait writes Unit.
server_loop
BEAM-style server loop: receive_match → handle → send_reply → repeat.
supervised_tree
Root (started by a host crate::Supervisor) starts a parked worker, then exit/2s it. Returns 1 when the worker was alive and DOWN is Fault.
waiting_send
Client arity 1 (r0 = server Cap) sends two hops; server drains both. With mailbox capacity 1 the second send parks (WAITING_SEND).