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

Function drop_call_async_future

tests/all/component_model/func.rs:3407–3448  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3405
3406#[tokio::test]
3407async fn drop_call_async_future() -> Result<()> {
3408 let component = r#"
3409(component
3410 (import "foo" (func $f))
3411 (core module $m
3412 (func $f (import "" "foo"))
3413 (func (export "foo") call $f)
3414 )
3415 (core func $f (canon lower (func $f)))
3416 (core instance $m (instantiate $m (with "" (instance
3417 (export "foo" (func $f))
3418 ))))
3419 (func (export "foo") (canon lift (core func $m "foo")))
3420)
3421"#;
3422
3423 let engine = &Engine::new(&Config::new())?;
3424 let component = Component::new(&engine, component)?;
3425 let mut store = Store::new(&engine, ());
3426 let mut linker = Linker::new(&engine);
3427 linker.root().func_wrap_async("foo", |_, _: ()| {
3428 Box::new(async {
3429 tokio::task::yield_now().await;
3430 Ok(())
3431 })
3432 })?;
3433 let instance = linker.instantiate_async(&mut store, &component).await?;
3434 let foo = instance.get_typed_func::<(), ()>(&mut store, "foo")?;
3435 // Here we'll use `call_async` a few times but only poll each returned
3436 // future once. This will put the instance in a weird state but shouldn't
3437 // cause a panic.
3438 for _ in 0..5 {
3439 let mut future = std::pin::pin!(foo.call_async(&mut store, ()));
3440 if let std::task::Poll::Ready(result) =
3441 std::future::poll_fn(|cx| std::task::Poll::Ready(future.as_mut().poll(cx))).await
3442 {
3443 _ = result;
3444 }
3445 }
3446
3447 Ok(())
3448}
3449
3450#[test]
3451fn host_call_with_concurrency_disabled() -> Result<()> {

Callers

nothing calls this directly

Calls 8

yield_nowFunction · 0.85
OkFunction · 0.85
newFunction · 0.50
func_wrap_asyncMethod · 0.45
rootMethod · 0.45
instantiate_asyncMethod · 0.45
pollMethod · 0.45
as_mutMethod · 0.45

Tested by

no test coverage detected