1use async_trait::async_trait;
4
5#[cfg_attr(feature = "multithreaded", async_trait)]
6#[cfg_attr(not(feature="multithreaded"), async_trait(?Send))]
7pub trait Runtime {
8 async fn sleep(dur: std::time::Duration);
9}
10
11pub struct DefaultRuntime;
14
15#[cfg_attr(feature = "multithreaded", async_trait)]
16#[cfg_attr(not(feature="multithreaded"), async_trait(?Send))]
17impl Runtime for DefaultRuntime {
18 async fn sleep(dur: std::time::Duration) {
19 std::thread::sleep(dur);
20 }
21}
22
23#[cfg(feature = "tokio")]
24pub struct TokioRuntime;
25
26#[cfg(feature = "tokio")]
27#[cfg_attr(feature = "multithreaded", async_trait)]
28#[cfg_attr(not(feature="multithreaded"), async_trait(?Send))]
29impl Runtime for TokioRuntime {
30 async fn sleep(dur: std::time::Duration) {
31 tokio::time::sleep(dur).await
32 }
33}