I have host state that contains methods which need to perform async operations. With the generated Host trait, calling these async methods is straightforward. However, I'm struggling to find the correct pattern to do this with HostWithStore:
impl HostWithStore for MyState {
async fn my_func(accessor: Accessor<T, Self>) -> wasmtime::Result<()> {
// The accessor.with() closure is synchronous.
accessor.with(|access| {
let state = access.get();
// state.do_async_work().await; // won't compile
How can I correctly invoke an async method on MyState within this pattern?
Is there a way to call the async function on MyState?
What you'll effectively want to do at this time is "take out" bits from the store, await them outside of .with(...), and then put them back in afterwards. It's not great right now and we're open to finding better idioms/solutions, but this is the best way we know of to map component model semantics onto rust.
Notably the guest can invoke my_func many times while they're all processing, where previously that was not possible in wasm
Last updated: Dec 06 2025 at 06:05 UTC