use rvtime::{Config, Engine, Linker, Module, Store};
use std::{thread, time::Duration};
const GUEST: &[u8] = include_bytes!("../../../fixtures/hosted.elf");
fn main() -> anyhow::Result<()> {
let mut config = Config::default();
config.interruptible(true);
let engine = Engine::new(&config)?;
let module = Module::new(&engine, GUEST)?;
let mut store = Store::new(&engine, ());
let instance = Linker::new(&engine).instantiate(&mut store, &module)?;
let handle = store.interrupt_handle()?;
let spin = instance.get_typed_func::<(u64,), u64>("spin")?;
let guest = thread::spawn(move || spin.call(&mut store, (0,)));
thread::sleep(Duration::from_millis(100));
println!("asking the guest to stop");
handle.interrupt();
match guest.join().expect("the guest thread panicked") {
Ok(value) => println!("returned {value} -- unexpected, `spin` should not return"),
Err(error) => println!("stopped: {error}"),
}
Ok(())
}