Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/wasi-common/src/tokio/sched.rs
1692 views
1
#[cfg(unix)]
2
mod unix;
3
#[cfg(unix)]
4
pub use unix::poll_oneoff;
5
6
#[cfg(windows)]
7
mod windows;
8
#[cfg(windows)]
9
pub use windows::poll_oneoff;
10
11
use crate::{
12
Error,
13
sched::{Duration, Poll, WasiSched},
14
};
15
16
pub fn sched_ctx() -> Box<dyn crate::WasiSched> {
17
struct AsyncSched;
18
19
#[wiggle::async_trait]
20
impl WasiSched for AsyncSched {
21
async fn poll_oneoff<'a>(&self, poll: &mut Poll<'a>) -> Result<(), Error> {
22
poll_oneoff(poll).await
23
}
24
async fn sched_yield(&self) -> Result<(), Error> {
25
tokio::task::yield_now().await;
26
Ok(())
27
}
28
async fn sleep(&self, duration: Duration) -> Result<(), Error> {
29
tokio::time::sleep(duration).await;
30
Ok(())
31
}
32
}
33
34
Box::new(AsyncSched)
35
}
36
37