1 #[cfg(unix)]
2 pub mod unix;
3 #[cfg(unix)]
4 pub use unix::poll_oneoff;
5 
6 #[cfg(windows)]
7 pub mod windows;
8 #[cfg(windows)]
9 pub use windows::poll_oneoff;
10 
11 use crate::{
12     Error,
13     sched::{Poll, WasiSched},
14 };
15 use std::thread;
16 use std::time::Duration;
17 
18 pub struct SyncSched {}
19 impl SyncSched {
new() -> Self20     pub fn new() -> Self {
21         Self {}
22     }
23 }
24 #[async_trait::async_trait]
25 impl WasiSched for SyncSched {
poll_oneoff<'a>(&self, poll: &mut Poll<'a>) -> Result<(), Error>26     async fn poll_oneoff<'a>(&self, poll: &mut Poll<'a>) -> Result<(), Error> {
27         poll_oneoff(poll).await
28     }
sched_yield(&self) -> Result<(), Error>29     async fn sched_yield(&self) -> Result<(), Error> {
30         thread::yield_now();
31         Ok(())
32     }
sleep(&self, duration: Duration) -> Result<(), Error>33     async fn sleep(&self, duration: Duration) -> Result<(), Error> {
34         std::thread::sleep(duration);
35         Ok(())
36     }
37 }
sched_ctx() -> Box<dyn WasiSched>38 pub fn sched_ctx() -> Box<dyn WasiSched> {
39     Box::new(SyncSched::new())
40 }
41