1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use alloc::boxed::Box;
use core::time::Duration;

pub use async_timer::timer::{Platform, Platform as AsyncTimerPlatform};

use crate::{Sleepble, SleepbleWaitBoxFuture};

//
impl Sleepble for Platform {
    fn sleep(dur: Duration) -> Self {
        Self::new(dur)
    }

    fn wait(self) -> SleepbleWaitBoxFuture {
        Box::pin(self)
    }
}

#[cfg(test)]
mod tests {
    #[allow(unused_imports)]
    use super::*;

    #[cfg(feature = "std")]
    #[tokio::test]
    async fn test_sleep() {
        #[cfg(feature = "std")]
        let now = std::time::Instant::now();

        crate::sleep::sleep::<Platform>(Duration::from_millis(100)).await;

        #[cfg(feature = "std")]
        {
            let elapsed_dur = now.elapsed();
            assert!(elapsed_dur.as_millis() >= 100 && elapsed_dur.as_millis() <= 105);
        }
    }
}