Skip to main content

atomic_request_reply

Function atomic_request_reply 

Source
pub fn atomic_request_reply() -> Chunk
Expand description

Atomic request-reply with crate::Value::Message (one envelope per hop).

Examples found in repository?
examples/atomic_actors.rs (line 22)
21fn main() {
22    let chunk = samples::atomic_request_reply();
23    let rt = match Runtime::with_natives_and_config(
24        chunk,
25        std_native_table(),
26        RuntimeConfig {
27            workers: 2,
28            quantum: 10_000,
29            mailbox: byteflow::MailboxConfig::DEFAULT,
30            ..Default::default()
31        },
32    ) {
33        Ok(rt) => rt,
34        Err(e) => {
35            eprintln!("runtime: {e}");
36            std::process::exit(1);
37        }
38    };
39    let Some(main) = rt.function_index("main") else {
40        eprintln!("missing main");
41        std::process::exit(1);
42    };
43    let handle = match rt.spawn(main, &[]) {
44        Ok(h) => h,
45        Err(e) => {
46            eprintln!("spawn: {e}");
47            std::process::exit(1);
48        }
49    };
50    let outcome = handle.join();
51    let metrics = rt.metrics();
52    rt.shutdown();
53
54    match outcome {
55        FlowOutcome::Completed(Value::Int(42)) => {
56            println!("atomic request-reply ok: payload=42");
57            println!("{metrics}");
58        }
59        other => {
60            eprintln!("unexpected {other:?}");
61            std::process::exit(1);
62        }
63    }
64}