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

Function run_wasm_in_call_async

tests/all/component_model/async.rs:410–475  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

408#[tokio::test]
409#[cfg_attr(miri, ignore)]
410async fn run_wasm_in_call_async() -> Result<()> {
411 _ = env_logger::try_init();
412
413 let mut config = Config::new();
414 config.wasm_component_model_async(true);
415 let engine = Engine::new(&config)?;
416
417 let a = Component::new(
418 &engine,
419 r#"
420(component
421 (type $t (func async))
422 (import "a" (func $f (type $t)))
423 (core func $f (canon lower (func $f)))
424 (core module $a
425 (import "" "f" (func $f))
426 (func (export "run") call $f)
427 )
428 (core instance $a (instantiate $a
429 (with "" (instance (export "f" (func $f))))
430 ))
431 (func (export "run") (type $t)
432 (canon lift (core func $a "run")))
433)
434 "#,
435 )?;
436 let b = Component::new(
437 &engine,
438 r#"
439(component
440 (type $t (func async))
441 (core module $a
442 (func (export "run"))
443 )
444 (core instance $a (instantiate $a))
445 (func (export "run") (type $t)
446 (canon lift (core func $a "run")))
447)
448 "#,
449 )?;
450
451 type State = Option<Instance>;
452
453 let mut linker = Linker::new(&engine);
454 linker
455 .root()
456 .func_wrap_concurrent("a", |accessor: &Accessor<State>, (): ()| {
457 Box::pin(async move {
458 let func = accessor.with(|mut access| {
459 access
460 .get()
461 .unwrap()
462 .get_typed_func::<(), ()>(&mut access, "run")
463 })?;
464 func.call_concurrent(accessor, ()).await?;
465 Ok(())
466 })
467 })?;

Callers

nothing calls this directly

Calls 12

OkFunction · 0.85
call_concurrentMethod · 0.80
newFunction · 0.50
func_wrap_concurrentMethod · 0.45
rootMethod · 0.45
withMethod · 0.45
unwrapMethod · 0.45
getMethod · 0.45
instantiate_asyncMethod · 0.45
data_mutMethod · 0.45
call_asyncMethod · 0.45

Tested by

no test coverage detected