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.
| Sample | Shows |
|---|---|
add_forty_two | Scalar VM path (no natives) |
ping_pong | Cap spawn + Atomic Hop round-trip |
atomic_request_reply | Tagged REQ/REP + correlated receive |
atomic_actors | Server loop + two Ask clients + minted request_id |
cap_in_payload | Cap in hop payload is reissued to the recipient |
cap_in_list | Cap nested in a List is reissued the same way |
selective_receive | ReceiveMatch FIFO skip |
selective_receive_timeout | BEAM after: ReceiveMatchImmTimeout → Unit |
selective_receive_after | after still skips junk and hits the tag |
process_alive | IsAlive (BEAM is_process_alive/1) |
process_dict | process dictionary put / get / erase |
receive_match_eq | term equality: tag + Int payload |
exit_signal | BEAM exit/2 → DOWN with Fault |
supervised_tree | bytecode StartChild under a host supervisor |
receive_match_kind | ReceiveMatchKind by payload wire-tag |
ask_reply | Ask RPC hop |
ask_timeout_expires | AskTimeout writes Unit when the server stays silent |
ask_target_exits | Ask dest is TAG_SYS_EXIT when the server dies first |
server_loop | BEAM-style receive → handle → reply loop |
named_service | Bytecode register_name / whereis (Cap, not FlowId) |
forged_sender_send / forged_sender_ask | S1: forged make_msg sender dies |
boom | Immediate trap (supervisor demos) |
monitor_down | Monitor → crate::TAG_SYS_DOWN on child exit |
waiting_send | WAITING_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.
§Flow / “actor” patterns (all correct when used in the right role)
| Role | Pattern | Examples |
|---|---|---|
| Long-lived service | Fn::actor_loop + send_reply | server_loop, named_service, atomic_actors server, ask_reply |
| One-shot worker | receive_match_imm(tag) → handle → send_reply → exit | ping_pong pong, atomic_request_reply server, [cap_in_*] |
| RPC client | [Fn::ask] / ask_timeout + hop_fresh | atomic_actors client, ask_reply main |
| Cast client | send / cast + receive_match_corr_imm or receive_match_imm | ping_pong main, selective_receive |
Prefer shared tags in TAG_REQ / TAG_REP / …; mint ids with [Fn::hop_fresh]
when correlating multiple in-flight hops on one flow.
Constants§
- TAG_
DONE - Client → parent completion hop in
atomic_actors(not an RPC reply). - TAG_
JUNK - Decoy hop for
selective_receive— must be skipped byReceiveMatch. - TAG_
PING - TAG_
PONG - TAG_
READY - Readiness handshake (e.g.
SetTrapExitbefore 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). Server uses [Fn::actor_loop] so repeatedAsks on the same Cap stay valid (CLI / long-lived service). - ask_
target_ exits - Server takes the request and exits; client
Askmust not hang. - ask_
timeout_ expires AskTimeoutagainst a server that never replies →Unit.- atomic_
actors - Canonical Atomic Hop actor demo: one server loop, two clients, each
doing
NAsks with mintedrequest_ids. Each client asserts that the reply echoes the request’srequest_idbefore 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 showcrate::Supervisorrestart. - 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
42back through it. Exercises hop-time reissue (holder becomes the recipient). - exit_
signal - BEAM
exit/2: child parked on receive dies withFault; monitor payload is3. - forged_
sender_ ask - Same security property as
forged_sender_send, viaAsk. - forged_
sender_ send - Security regression: forged
make_msgsender must not surviveSend. - monitor_
down - Child sleeps then exits; parent monitors and returns the
DOWNreason (0= normal). - named_
service - Server publishes
"svc"; client loopswhereisuntil it gets a SEND Cap (not ASK — useSend+Receive, notAsk). Returns42(41 + 1). Discovery never exposes a raw FlowId. - ping_
pong - Two flows, one Atomic Hop round-trip:
mainsends aMessagetopong,pongreplies with payload+1 viamsg_reply_cap,mainreturns that payload (2). - process_
alive - BEAM
is_process_alive/1: a parked child is live; afterDOWN, its Cap is not. - process_
dict - Process dictionary (
put/get/erase): store 41, add 1 in a register, erase still yields the stored 41. Returns42 + 41 = 83. - receive_
match_ eq - Term equality receive: skip a
TAG_REQwhose payload is0, take41. - receive_
match_ kind - Selective receive by payload wire-tag (
ReceiveMatchKind): skip hops whose payload is notInt(tag 2), then reply with that payload. - selective_
receive - Selective Atomic Hop: server waits for
TAG_REQwhile aTAG_JUNKhop sits ahead in the mailbox (FIFO skip, not drop). - selective_
receive_ after - Selective receive +
after: junk stays queued,TAG_REQarrives in time. - selective_
receive_ timeout - BEAM
receive … after: nobody sendsTAG_REQ, so the wait writesUnit. - 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, thenexit/2s it. Returns1when the worker was alive andDOWNisFault. - waiting_
send - Client arity 1 (
r0= server Cap) sends two hops; server drains both. With mailbox capacity 1 the second send parks (WAITING_SEND).