wasi-tokio: WIP need to port the sync scheduler into a spawn_blocking

This commit is contained in:
Pat Hickey
2021-04-19 16:00:38 -07:00
parent 8667d8c244
commit 3d3a2acc1b
5 changed files with 464 additions and 21 deletions

View File

@@ -1,5 +1,6 @@
mod dir;
mod file;
mod sched;
use std::cell::RefCell;
use std::path::Path;
@@ -7,27 +8,7 @@ use std::rc::Rc;
pub use wasi_cap_std_sync::{clocks_ctx, random_ctx, Dir};
use wasi_common::{Error, Table, WasiCtx};
pub fn sched_ctx() -> Box<dyn wasi_common::WasiSched> {
use wasi_common::sched::{Duration, Poll, WasiSched};
struct AsyncSched;
#[wiggle::async_trait]
impl WasiSched for AsyncSched {
async fn poll_oneoff<'a>(&self, _poll: &'_ Poll<'a>) -> Result<(), Error> {
todo!()
}
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)
}
use crate::sched::sched_ctx;
pub struct WasiCtxBuilder(wasi_common::WasiCtxBuilder);