Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/test-programs/src/bin/async_yield_callee_synchronous.rs
3092 views
1
mod bindings {
2
wit_bindgen::generate!({
3
path: "../misc/component-async-tests/wit",
4
world: "yield-callee",
5
async: ["-local:local/run#run"],
6
});
7
8
use super::Component;
9
export!(Component);
10
}
11
12
use bindings::{exports::local::local::run::Guest, local::local::continue_};
13
14
#[cfg(not(target_arch = "wasm32"))]
15
unsafe fn yield_cancellable() -> bool {
16
unreachable!();
17
}
18
19
#[cfg(target_arch = "wasm32")]
20
#[link(wasm_import_module = "$root")]
21
unsafe extern "C" {
22
#[link_name = "[cancellable][thread-yield]"]
23
fn yield_cancellable() -> bool;
24
}
25
26
struct Component;
27
28
impl Guest for Component {
29
fn run() {
30
while continue_::get_continue() && unsafe { !yield_cancellable() } {}
31
}
32
}
33
34
// Unused function; required since this file is built as a `bin`:
35
fn main() {}
36
37