07 — Send, ask, deadlines¶
Agents communicate with three operators:
| Operator | Meaning |
|---|---|
target!Msg(args) |
fire-and-forget send |
target?Msg(args) |
ask-and-await reply |
expr @ duration |
apply a deadline to expr |
The program¶
fn driver(logger: Logger, fetcher: Fetcher, url: Url) -> Page!FetchErr {
logger!Info("started")
let page = fetcher?Page(url) @2s?
Ok(page)
}
What is interesting¶
logger!Info("started")sendsInfo("started")tologger. It does not wait for any reply; the caller continues immediately.fetcher?Page(url) @2s?is three operators stacked:?Page(url)asksfetcherfor a reply to messagePage(url), suspending the current task until a reply arrives.@2sattaches a 2-second deadline. If the reply does not arrive within 2 seconds, the ask fails withMT5011 deadline_exceeded(or a typed-error variant when the protocol declares one).- The trailing
?propagates that error (or any reply error) out ofdriverasFetchErr. - Duration literals (
2s,100ms,5us) are first-class tokens in the grammar — see the lexer.
Try it¶
Runtime semantics (v0.7+)¶
!Msgenqueues into the target agent's mailbox and returns immediately. If the mailbox is full and the budget policy isblock(the default) the sender back-pressures;droporfailpolicies surfaceMT5012 mailbox_full.?Msg @Dcreates a oneshot reply channel, enqueues, andawaits the channel with deadlineD. Expiry is observed by the caller asResult::Err(DeadlineExceeded).- If the target is dead or unsupervised, the caller sees
MT5021 send_to_dead_agent.
Next¶
Continue to 08 — Supervisors.