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
39
40
41
42
43
44
45
46
//! Contains some utility features to create a [`Future`](/std/future/trait.Future.html) implementation
//! to be used in any async function.
//!
//! # Examples
//!
//! Create a [`Future`](/std/future/trait.Future.html) to be ready after some point:
//!
//! ```
//! use std::time::Duration;
//! use settimeout::set_timeout;
//! use futures::executor::block_on;
//!
//! async fn foo() {
//!   println!("The Future will be ready after some time");
//!   set_timeout(Duration::from_secs(5)).await;
//!   println!("Now, it is ready");
//! }
//!
//! block_on(foo());
//! ```

pub use timer::set_timeout;
pub use timer::Timer;

mod timer;

#[cfg(test)]
mod tests {
    use super::*;
    use futures::executor::block_on;
    use std::time::Duration;

    #[test]
    fn set_timeout_should_wait() {
        block_on(async {
            set_timeout(Duration::from_secs(2)).await;
        });
    }

    #[test]
    fn timer_should_wait() {
        block_on(async {
            Timer::new(Duration::from_secs(2)).await;
        });
    }
}