wasi-tokio: WIP need to port the sync scheduler into a spawn_blocking
This commit is contained in:
35
crates/wasi-common/tokio/src/sched.rs
Normal file
35
crates/wasi-common/tokio/src/sched.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
#[cfg(unix)]
|
||||
mod unix;
|
||||
#[cfg(unix)]
|
||||
use unix::poll_oneoff;
|
||||
|
||||
#[cfg(windows)]
|
||||
mod windows;
|
||||
#[cfg(windows)]
|
||||
use windows::poll_oneoff;
|
||||
|
||||
use wasi_common::{
|
||||
sched::{Duration, Poll, WasiSched},
|
||||
Error,
|
||||
};
|
||||
|
||||
pub fn sched_ctx() -> Box<dyn wasi_common::WasiSched> {
|
||||
struct AsyncSched;
|
||||
|
||||
#[wiggle::async_trait]
|
||||
impl WasiSched for AsyncSched {
|
||||
async fn poll_oneoff<'a>(&self, poll: &'_ Poll<'a>) -> Result<(), Error> {
|
||||
poll_oneoff(poll).await
|
||||
}
|
||||
async fn sched_yield(&self) -> Result<(), Error> {
|
||||
tokio::task::yield_now().await;
|
||||
Ok(())
|
||||
}
|
||||
async fn sleep(&self, duration: Duration) -> Result<(), Error> {
|
||||
tokio::time::sleep(duration).await;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Box::new(AsyncSched)
|
||||
}
|
||||
Reference in New Issue
Block a user