async_sleep/
impl_async_timer.rs1use alloc::boxed::Box;
2use core::time::Duration;
3
4pub use async_timer::timer::{Platform, Platform as AsyncTimerPlatform};
5
6use crate::{Sleepble, SleepbleWaitBoxFuture};
7
8impl Sleepble for Platform {
10 fn sleep(dur: Duration) -> Self {
11 Self::new(dur)
12 }
13
14 fn wait(self) -> SleepbleWaitBoxFuture {
15 Box::pin(self)
16 }
17}
18
19#[cfg(test)]
20mod tests {
21 #[allow(unused_imports)]
22 use super::*;
23
24 #[cfg(feature = "std")]
25 #[tokio::test]
26 async fn test_sleep() {
27 #[cfg(feature = "std")]
28 let now = std::time::Instant::now();
29
30 crate::sleep::sleep::<Platform>(Duration::from_millis(100)).await;
31
32 #[cfg(feature = "std")]
33 {
34 let elapsed_dur = now.elapsed();
35 assert!(elapsed_dur.as_millis() >= 100 && elapsed_dur.as_millis() <= 105);
36 }
37 }
38}