1804060c8SJoel Dice mod bindings {
2804060c8SJoel Dice     wit_bindgen::generate!({
3804060c8SJoel Dice         path: "../misc/component-async-tests/wit",
4804060c8SJoel Dice         world: "yield-caller",
5804060c8SJoel Dice     });
6804060c8SJoel Dice 
7804060c8SJoel Dice     use super::Component;
8804060c8SJoel Dice     export!(Component);
9804060c8SJoel Dice }
10804060c8SJoel Dice 
11804060c8SJoel Dice use {
12804060c8SJoel Dice     bindings::{
13804060c8SJoel Dice         exports::local::local::run::Guest,
14804060c8SJoel Dice         local::local::{continue_, ready, run},
15804060c8SJoel Dice     },
16804060c8SJoel Dice     futures::future,
17804060c8SJoel Dice     std::{future::Future, task::Poll},
18804060c8SJoel Dice };
19804060c8SJoel Dice 
20804060c8SJoel Dice struct Component;
21804060c8SJoel Dice 
22804060c8SJoel Dice impl Guest for Component {
run()23804060c8SJoel Dice     async fn run() {
24*6ca03af1SJoel Dice         let thing = ready::Thing::new();
25*6ca03af1SJoel Dice         thing.set_ready(false);
26804060c8SJoel Dice         continue_::set_continue(true);
27804060c8SJoel Dice 
28*6ca03af1SJoel Dice         let mut ready = Some(Box::pin(thing.when_ready()));
29804060c8SJoel Dice         let mut run = Some(Box::pin(run::run()));
30*6ca03af1SJoel Dice         future::poll_fn(|cx| {
31804060c8SJoel Dice             let ready_poll = ready.as_mut().map(|v| v.as_mut().poll(cx));
32*6ca03af1SJoel Dice             thing.set_ready(true);
33804060c8SJoel Dice             let run_poll = run.as_mut().map(|v| v.as_mut().poll(cx));
34804060c8SJoel Dice 
35804060c8SJoel Dice             match (run_poll, ready_poll) {
36804060c8SJoel Dice                 (None | Some(Poll::Ready(())), None | Some(Poll::Ready(()))) => {
37804060c8SJoel Dice                     return Poll::Ready(());
38804060c8SJoel Dice                 }
39804060c8SJoel Dice                 (Some(Poll::Ready(())), _) => run = None,
40804060c8SJoel Dice                 (_, Some(Poll::Ready(()))) => {
41804060c8SJoel Dice                     ready = None;
42804060c8SJoel Dice                     continue_::set_continue(false);
43804060c8SJoel Dice                 }
44804060c8SJoel Dice                 _ => {}
45804060c8SJoel Dice             }
46804060c8SJoel Dice 
47804060c8SJoel Dice             Poll::Pending
48804060c8SJoel Dice         })
49804060c8SJoel Dice         .await
50804060c8SJoel Dice     }
51804060c8SJoel Dice }
52804060c8SJoel Dice 
53804060c8SJoel Dice // Unused function; required since this file is built as a `bin`:
main()54804060c8SJoel Dice fn main() {}
55