1 mod bindings { 2 wit_bindgen::generate!({ 3 path: "../misc/component-async-tests/wit", 4 world: "yield-caller", 5 }); 6 7 use super::Component; 8 export!(Component); 9 } 10 11 use { 12 bindings::{ 13 exports::local::local::run::Guest, 14 local::local::{continue_, ready}, 15 }, 16 test_programs::async_::{STATUS_RETURNED, STATUS_STARTED, subtask_cancel}, 17 }; 18 19 #[cfg(target_arch = "wasm32")] 20 #[link(wasm_import_module = "local:local/run")] 21 unsafe extern "C" { 22 #[link_name = "[async-lower][async]run"] 23 fn run() -> u32; 24 } 25 #[cfg(not(target_arch = "wasm32"))] 26 unsafe extern "C" fn run() -> u32 { 27 unreachable!() 28 } 29 30 struct Component; 31 32 impl Guest for Component { 33 async fn run() { 34 ready::set_ready(true); 35 continue_::set_continue(true); 36 37 unsafe { 38 let status = run(); 39 let waitable = status >> 4; 40 let status = status & 0xF; 41 assert_eq!(status, STATUS_STARTED); 42 43 // Here we assume the following: 44 // 45 // - Wasmtime will deliver a cancel event to the callee before returning 46 // from `subtask_cancel`. 47 // 48 // - The callee will immediately return as soon as it receives the 49 // event. 50 let status = subtask_cancel(waitable); 51 assert_eq!(status, STATUS_RETURNED); 52 } 53 } 54 } 55 56 // Unused function; required since this file is built as a `bin`: 57 fn main() {} 58