MCPcopy Index your code
hub / github.com/explodingcamera/tinywasm / main

Function main

examples/resumable.rs:25–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23"#;
24
25fn main() -> Result<()> {
26 let wasm = wat::parse_str(WASM)?;
27 let module = tinywasm::parse_bytes(&wasm)?;
28 let mut store = Store::default();
29 let instance = ModuleInstance::instantiate(&mut store, &module, None)?;
30 let count_down = instance.func::<i32, i32>(&store, "count_down")?;
31
32 let mut execution = count_down.call_resumable(&mut store, 10_000)?;
33 let fuel_per_round = 128;
34 let mut fuel_rounds = 0;
35
36 let result = loop {
37 fuel_rounds += 1;
38 match execution.resume_with_fuel(fuel_per_round)? {
39 ExecProgress::Completed(value) => break value,
40 ExecProgress::Suspended => {}
41 }
42 };
43
44 println!("completed in {fuel_rounds} rounds of {fuel_per_round} fuel, result={result}");
45 Ok(())
46}

Callers

nothing calls this directly

Calls 3

parse_bytesFunction · 0.85
call_resumableMethod · 0.80
resume_with_fuelMethod · 0.80

Tested by

no test coverage detected