settimeout/lib.rs
1//! Contains some utility features to create a [`Future`](/std/future/trait.Future.html) implementation
2//! to be used in any async function.
3//!
4//! # Examples
5//!
6//! Create a [`Future`](/std/future/trait.Future.html) to be ready after some point:
7//!
8//! ```
9//! use std::time::Duration;
10//! use settimeout::set_timeout;
11//! use futures::executor::block_on;
12//!
13//! async fn foo() {
14//! println!("The Future will be ready after some time");
15//! set_timeout(Duration::from_secs(5)).await;
16//! println!("Now, it is ready");
17//! }
18//!
19//! block_on(foo());
20//! ```
21
22pub use timer::set_timeout;
23pub use timer::Timer;
24
25mod timer;
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30 use futures::executor::block_on;
31 use std::time::Duration;
32
33 #[test]
34 fn set_timeout_should_wait() {
35 block_on(async {
36 set_timeout(Duration::from_secs(2)).await;
37 });
38 }
39
40 #[test]
41 fn timer_should_wait() {
42 block_on(async {
43 Timer::new(Duration::from_secs(2)).await;
44 });
45 }
46}