Path: blob/main/crates/test-programs/src/bin/async_yield_caller.rs
3070 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() {23let thing = ready::Thing::new();24thing.set_ready(false);25continue_::set_continue(true);2627let mut ready = Some(Box::pin(thing.when_ready()));28let mut run = Some(Box::pin(run::run()));29future::poll_fn(|cx| {30let ready_poll = ready.as_mut().map(|v| v.as_mut().poll(cx));31thing.set_ready(true);32let run_poll = run.as_mut().map(|v| v.as_mut().poll(cx));3334match (run_poll, ready_poll) {35(None | Some(Poll::Ready(())), None | Some(Poll::Ready(()))) => {36return Poll::Ready(());37}38(Some(Poll::Ready(())), _) => run = None,39(_, Some(Poll::Ready(()))) => {40ready = None;41continue_::set_continue(false);42}43_ => {}44}4546Poll::Pending47})48.await49}50}5152// Unused function; required since this file is built as a `bin`:53fn main() {}545556