Path: blob/main/crates/test-programs/src/bin/async_yield_caller.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, run},14},15futures::future,16std::{future::Future, task::Poll},17};1819struct Component;2021impl Guest for Component {22async fn run() {23ready::set_ready(false);24continue_::set_continue(true);2526let mut ready = Some(Box::pin(ready::when_ready()));27let mut run = Some(Box::pin(run::run()));28future::poll_fn(move |cx| {29let ready_poll = ready.as_mut().map(|v| v.as_mut().poll(cx));30ready::set_ready(true);31let run_poll = run.as_mut().map(|v| v.as_mut().poll(cx));3233match (run_poll, ready_poll) {34(None | Some(Poll::Ready(())), None | Some(Poll::Ready(()))) => {35return Poll::Ready(());36}37(Some(Poll::Ready(())), _) => run = None,38(_, Some(Poll::Ready(()))) => {39ready = None;40continue_::set_continue(false);41}42_ => {}43}4445Poll::Pending46})47.await48}49}5051// Unused function; required since this file is built as a `bin`:52fn main() {}535455