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 {
run()23     async fn run() {
24         let thing = ready::Thing::new();
25         thing.set_ready(false);
26         continue_::set_continue(true);
27 
28         let mut ready = Some(Box::pin(thing.when_ready()));
29         let mut run = Some(Box::pin(run::run()));
30         future::poll_fn(|cx| {
31             let ready_poll = ready.as_mut().map(|v| v.as_mut().poll(cx));
32             thing.set_ready(true);
33             let run_poll = run.as_mut().map(|v| v.as_mut().poll(cx));
34 
35             match (run_poll, ready_poll) {
36                 (None | Some(Poll::Ready(())), None | Some(Poll::Ready(()))) => {
37                     return Poll::Ready(());
38                 }
39                 (Some(Poll::Ready(())), _) => run = None,
40                 (_, Some(Poll::Ready(()))) => {
41                     ready = None;
42                     continue_::set_continue(false);
43                 }
44                 _ => {}
45             }
46 
47             Poll::Pending
48         })
49         .await
50     }
51 }
52 
53 // Unused function; required since this file is built as a `bin`:
main()54 fn main() {}
55