Path: blob/main/crates/test-programs/src/bin/async_yield_caller_cancel.rs
3050 views
mod bindings {1wit_bindgen::generate!({2path: "../misc/component-async-tests/wit",3world: "yield-caller",4});56use super::Component;7export!(Component);8}910use {11bindings::{exports::local::local::run::Guest, local::local::continue_},12test_programs::async_::{STATUS_RETURNED, STATUS_STARTED, subtask_cancel},13};1415#[cfg(target_arch = "wasm32")]16#[link(wasm_import_module = "local:local/run")]17unsafe extern "C" {18#[link_name = "[async-lower]run"]19fn run() -> u32;20}21#[cfg(not(target_arch = "wasm32"))]22unsafe extern "C" fn run() -> u32 {23unreachable!()24}2526struct Component;2728impl Guest for Component {29async fn run() {30continue_::set_continue(true);3132unsafe {33let status = run();34let waitable = status >> 4;35let status = status & 0xF;36assert_eq!(status, STATUS_STARTED);3738// Here we assume the following:39//40// - Wasmtime will deliver a cancel event to the callee before returning41// from `subtask_cancel`.42//43// - The callee will immediately return as soon as it receives the44// event.45let status = subtask_cancel(waitable);46assert_eq!(status, STATUS_RETURNED);47}48}49}5051// Unused function; required since this file is built as a `bin`:52fn main() {}535455