1 mod bindings {
2     wit_bindgen::generate!({
3         path: "../misc/component-async-tests/wit",
4         world: "yield-caller",
5     });
6 
7     use super::Component;
8     export!(Component);
9 }
10 
11 use {
12     bindings::{
13         exports::local::local::run::Guest,
14         local::local::{continue_, ready, run},
15     },
16     futures::future,
17     std::{future::Future, task::Poll},
18 };
19 
20 struct Component;
21 
22 impl Guest for Component {
23     async fn run() {
24         ready::set_ready(false);
25         continue_::set_continue(true);
26 
27         let mut ready = Some(Box::pin(ready::when_ready()));
28         let mut run = Some(Box::pin(run::run()));
29         future::poll_fn(move |cx| {
30             let ready_poll = ready.as_mut().map(|v| v.as_mut().poll(cx));
31             ready::set_ready(true);
32             let run_poll = run.as_mut().map(|v| v.as_mut().poll(cx));
33 
34             match (run_poll, ready_poll) {
35                 (None | Some(Poll::Ready(())), None | Some(Poll::Ready(()))) => {
36                     return Poll::Ready(());
37                 }
38                 (Some(Poll::Ready(())), _) => run = None,
39                 (_, Some(Poll::Ready(()))) => {
40                     ready = None;
41                     continue_::set_continue(false);
42                 }
43                 _ => {}
44             }
45 
46             Poll::Pending
47         })
48         .await
49     }
50 }
51 
52 // Unused function; required since this file is built as a `bin`:
53 fn main() {}
54