use wasmtime::*;
fn main() -> Result<()> {
let engine = Engine::new(Config::new().epoch_interruption(true))?;
let mut store = Store::new(&engine, ());
store.set_epoch_deadline(1);
let module = Module::from_file(&engine, "examples/interrupt.wat")?;
let instance = Instance::new(&mut store, &module, &[])?;
let run = instance.get_typed_func::<(), ()>(&mut store, "run")?;
std::thread::spawn(move || {
std::thread::sleep(std::time::Duration::from_secs(1));
println!("Interrupting!");
engine.increment_epoch();
});
println!("Entering infinite loop ...");
let err = run.call(&mut store, ()).unwrap_err();
println!("trap received...");
assert_eq!(err.downcast::<Trap>()?, Trap::Interrupt);
Ok(())
}