Path: blob/main/crates/test-programs/src/bin/async_yield_caller_cancel.rs
1693 views
mod bindings {1wit_bindgen::generate!({2path: "../misc/component-async-tests/wit",3world: "yield-caller",4});56use super::Component;7export!(Component);8}910use {11bindings::{12exports::local::local::run::Guest,13local::local::{continue_, ready},14},15test_programs::async_::{STATUS_RETURNED, STATUS_STARTED, subtask_cancel},16};1718#[cfg(target_arch = "wasm32")]19#[link(wasm_import_module = "local:local/run")]20unsafe extern "C" {21#[link_name = "[async-lower][async]run"]22fn run() -> u32;23}24#[cfg(not(target_arch = "wasm32"))]25unsafe extern "C" fn run() -> u32 {26unreachable!()27}2829struct Component;3031impl Guest for Component {32async fn run() {33ready::set_ready(true);34continue_::set_continue(true);3536unsafe {37let status = run();38let waitable = status >> 4;39let status = status & 0xF;40assert_eq!(status, STATUS_STARTED);4142// Here we assume the following:43//44// - Wasmtime will deliver a cancel event to the callee before returning45// from `subtask_cancel`.46//47// - The callee will immediately return as soon as it receives the48// event.49let status = subtask_cancel(waitable);50assert_eq!(status, STATUS_RETURNED);51}52}53}5455// Unused function; required since this file is built as a `bin`:56fn main() {}575859