MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / call_wrapped_async_func

Function call_wrapped_async_func

tests/all/component_model/call_hook.rs:186–246  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

184// Create an async Func, call it directly:
185#[tokio::test]
186async fn call_wrapped_async_func() -> Result<()> {
187 let wat = r#"
188 (component
189 (import "f" (func $f))
190
191 (core func $f_lower
192 (canon lower (func $f))
193 )
194 (core module $m
195 (import "" "" (func $f))
196
197 (func $export
198 (call $f)
199 )
200
201 (export "export" (func $export))
202 )
203 (core instance $i (instantiate $m
204 (with "" (instance
205 (export "" (func $f_lower))
206 ))
207 ))
208 (func (export "export")
209 (canon lift
210 (core func $i "export")
211 )
212 )
213 )
214 "#;
215
216 let engine = Engine::default();
217
218 let component = Component::new(&engine, wat)?;
219
220 let mut linker = Linker::<State>::new(&engine);
221 linker
222 .root()
223 .func_wrap_async("f", |_, _: ()| Box::new(async { Ok(()) }))?;
224
225 let mut store = Store::new(&engine, State::default());
226 store.call_hook(sync_call_hook);
227
228 let inst = linker
229 .instantiate_async(&mut store, &component)
230 .await
231 .expect("instantiate");
232
233 let export = inst
234 .get_typed_func::<(), ()>(&mut store, "export")
235 .expect("looking up `export`");
236
237 export.call_async(&mut store, ()).await?;
238
239 let s = store.into_data();
240 assert_eq!(s.calls_into_host, 1);
241 assert_eq!(s.returns_from_host, 1);
242 assert_eq!(s.calls_into_wasm, 1);
243 assert_eq!(s.returns_from_wasm, 1);

Callers

nothing calls this directly

Calls 9

OkFunction · 0.85
into_dataMethod · 0.80
newFunction · 0.50
func_wrap_asyncMethod · 0.45
rootMethod · 0.45
call_hookMethod · 0.45
expectMethod · 0.45
instantiate_asyncMethod · 0.45
call_asyncMethod · 0.45

Tested by

no test coverage detected