Path: blob/main/crates/wasi-common/src/sync/sched.rs
1693 views
#[cfg(unix)]1pub mod unix;2#[cfg(unix)]3pub use unix::poll_oneoff;45#[cfg(windows)]6pub mod windows;7#[cfg(windows)]8pub use windows::poll_oneoff;910use crate::{11Error,12sched::{Poll, WasiSched},13};14use std::thread;15use std::time::Duration;1617pub struct SyncSched {}18impl SyncSched {19pub fn new() -> Self {20Self {}21}22}23#[wiggle::async_trait]24impl WasiSched for SyncSched {25async fn poll_oneoff<'a>(&self, poll: &mut Poll<'a>) -> Result<(), Error> {26poll_oneoff(poll).await27}28async fn sched_yield(&self) -> Result<(), Error> {29thread::yield_now();30Ok(())31}32async fn sleep(&self, duration: Duration) -> Result<(), Error> {33std::thread::sleep(duration);34Ok(())35}36}37pub fn sched_ctx() -> Box<dyn WasiSched> {38Box::new(SyncSched::new())39}404142