Jeff Vander Stoep | bf37273 | 2021-02-18 09:39:46 +0100 | [diff] [blame] | 1 | #![warn(rust_2018_idioms)] |
2 | |||||
3 | use tokio::time::{sleep_until, Duration, Instant}; | ||||
4 | use tokio_test::block_on; | ||||
5 | |||||
6 | #[test] | ||||
7 | fn async_block() { | ||||
8 | assert_eq!(4, block_on(async { 4 })); | ||||
9 | } | ||||
10 | |||||
11 | async fn five() -> u8 { | ||||
12 | 5 | ||||
13 | } | ||||
14 | |||||
15 | #[test] | ||||
16 | fn async_fn() { | ||||
17 | assert_eq!(5, block_on(five())); | ||||
18 | } | ||||
19 | |||||
20 | #[test] | ||||
21 | fn test_sleep() { | ||||
22 | let deadline = Instant::now() + Duration::from_millis(100); | ||||
23 | |||||
24 | block_on(async { | ||||
25 | sleep_until(deadline).await; | ||||
26 | }); | ||||
27 | } |