LeoDreamer2004 edited issue #12016:
I'm working on a WebAssembly interface with an async function defined in WIT:
package allay:plugin@1.0.0; world plugin { export test: async func() -> string; }I'm using
wasmtime::component::bindgen!to generate the bindings:wasmtime::component::bindgen!({ path: "wit", world: "plugin" });When I try to call the
testfunction:let instance = Plugin::instantiate(&mut store, &component, &linker)?; instance.call_test().await?;I encountered an issue. After expanding the macros, I found that the signature of
call_testis:pub async fn call_test<T, D>(&self, accessor: &Accessor) -> Result<String>;Unlike
Store, theAccessortype cannot be directly constructed by the user. What should I do in this situation? I would appreciate any guidance on how to resolve this.Thanks in advance for your help!
primoly commented on issue #12016:
I believe you’ll need wasmtime::component::Instance::run_concurrent.
Here’s some demo code I think would work:
let config = wasmtime::Config::new(); let engine = wasmtime::Engine::new(&config)?; let mut store = wasmtime::Store::new(&engine, ()); let component = wasmtime::component::Component::from_file(&engine, "plugin.wasm")?; let linker = wasmtime::component::Linker::new(&engine); let instance: wasmtime::component::Instance = linker.instantiate(&mut store, &component)?; let plugin = Plugin::instantiate(&mut store, &component, &linker)?; let test_result = instance .run_concurrent(&mut store, async |accessor| -> wasmtime::Result<String> { plugin.call_test(accessor).await }) .await??;
LeoDreamer2004 commented on issue #12016:
It works! Many thanks
LeoDreamer2004 closed issue #12016:
I'm working on a WebAssembly interface with an async function defined in WIT:
package allay:plugin@1.0.0; world plugin { export test: async func() -> string; }I'm using
wasmtime::component::bindgen!to generate the bindings:wasmtime::component::bindgen!({ path: "wit", world: "plugin" });When I try to call the
testfunction:let instance = Plugin::instantiate(&mut store, &component, &linker)?; instance.call_test().await?;I encountered an issue. After expanding the macros, I found that the signature of
call_testis:pub async fn call_test<T, D>(&self, accessor: &Accessor) -> Result<String>;Unlike
Store, theAccessortype cannot be directly constructed by the user. What should I do in this situation? I would appreciate any guidance on how to resolve this.Thanks in advance for your help!
Last updated: Dec 06 2025 at 07:03 UTC