use anyhow::Result;
use wasmtime::{Func, Instance, Module, Store};
use wasmtime_async::prelude::*;
fn main() -> Result<()> {
let store = Store::default();
let module = Module::from_file(&store, "examples/hello.wat")?;
let hello_func = Func::wrap_async(&store, || async {
smol::blocking!(println!("Hello World!"));
});
let imports = [hello_func.into()];
let instance = Instance::new(&module, &imports)?;
let run = instance
.get_func("run")
.ok_or(anyhow::format_err!("failed to find `run` function export"))?
.get_async()
.get0::<()>()?;
smol::run(async {
let mut stack = wasmtime_async::Stack::new(16 * 1024)?;
run(&mut stack).await?;
run(&mut stack).await?;
Ok::<_, anyhow::Error>(())
})?;
Ok(())
}