()
| 247 | #[tokio::test] |
| 248 | #[cfg_attr(miri, ignore)] |
| 249 | async fn drop_resource_async() -> Result<()> { |
| 250 | use std::sync::Arc; |
| 251 | use std::sync::Mutex; |
| 252 | |
| 253 | let engine = super::async_engine(); |
| 254 | let c = Component::new( |
| 255 | &engine, |
| 256 | r#" |
| 257 | (component |
| 258 | (import "t" (type $t (sub resource))) |
| 259 | |
| 260 | (core func $drop (canon resource.drop $t)) |
| 261 | |
| 262 | (core module $m |
| 263 | (import "" "drop" (func $drop (param i32))) |
| 264 | (func (export "f") (param i32) |
| 265 | (call $drop (local.get 0)) |
| 266 | ) |
| 267 | ) |
| 268 | (core instance $i (instantiate $m |
| 269 | (with "" (instance |
| 270 | (export "drop" (func $drop)) |
| 271 | )) |
| 272 | )) |
| 273 | |
| 274 | (func (export "f") (param "x" (own $t)) |
| 275 | (canon lift (core func $i "f"))) |
| 276 | ) |
| 277 | "#, |
| 278 | )?; |
| 279 | |
| 280 | struct MyType; |
| 281 | |
| 282 | let mut store = Store::new(&engine, ()); |
| 283 | let mut linker = Linker::new(&engine); |
| 284 | |
| 285 | let drop_status = Arc::new(Mutex::new("not dropped")); |
| 286 | let ds = drop_status.clone(); |
| 287 | |
| 288 | linker |
| 289 | .root() |
| 290 | .resource_async("t", ResourceType::host::<MyType>(), move |_, _| { |
| 291 | let ds = ds.clone(); |
| 292 | Box::new(async move { |
| 293 | *ds.lock().unwrap() = "before yield"; |
| 294 | tokio::task::yield_now().await; |
| 295 | *ds.lock().unwrap() = "after yield"; |
| 296 | Ok(()) |
| 297 | }) |
| 298 | })?; |
| 299 | let i = linker.instantiate_async(&mut store, &c).await?; |
| 300 | let f = i.get_typed_func::<(Resource<MyType>,), ()>(&mut store, "f")?; |
| 301 | |
| 302 | execute_across_threads(async move { |
| 303 | let resource = Resource::new_own(100); |
| 304 | f.call_async(&mut store, (resource,)).await?; |
| 305 | Ok::<_, wasmtime::Error>(()) |
| 306 | }) |
nothing calls this directly
no test coverage detected