1 #![expect(unsafe_op_in_unsafe_fn, reason = "old code, not worth updating yet")] 2 3 mod bindings { 4 wit_bindgen::generate!({ 5 path: "../misc/component-async-tests/wit", 6 world: "yield-callee", 7 }); 8 } 9 10 use { 11 bindings::local::local::continue_, 12 test_programs::async_::{CALLBACK_CODE_EXIT, CALLBACK_CODE_YIELD, EVENT_CANCELLED, EVENT_NONE}, 13 }; 14 15 #[cfg(target_arch = "wasm32")] 16 #[link(wasm_import_module = "[export]local:local/run")] 17 unsafe extern "C" { 18 #[link_name = "[task-return]run"] 19 fn task_return_run(); 20 } 21 #[cfg(not(target_arch = "wasm32"))] 22 unsafe extern "C" fn task_return_run() { 23 unreachable!() 24 } 25 26 #[unsafe(export_name = "[async-lift]local:local/run#run")] 27 unsafe extern "C" fn export_run() -> u32 { 28 callback_run(EVENT_NONE, 0, 0) 29 } 30 31 #[unsafe(export_name = "[callback][async-lift]local:local/run#run")] 32 unsafe extern "C" fn callback_run(event0: u32, _event1: u32, _event2: u32) -> u32 { 33 assert!(event0 == EVENT_NONE || event0 == EVENT_CANCELLED); 34 35 if continue_::get_continue() && event0 == EVENT_NONE { 36 CALLBACK_CODE_YIELD 37 } else { 38 task_return_run(); 39 CALLBACK_CODE_EXIT 40 } 41 } 42 43 // Unused function; required since this file is built as a `bin`: 44 fn main() {} 45