mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00

## Motivation Similar to #1666, it is no longer necessary to lazily register delays with the executions default timer. All delays are expected to be created from within a runtime, and should panic if not done so. ## Solution `tokio::time` now assumes there to be a `CURRENT_TIMER` set when creating a delay; this can be assumed if called within a tokio runtime. If there is no current timer, the application will panic with a "no current timer" message. ## Follow-up Similar to #1666, `HandlePriv` can probably be removed, but this mainly prepares for 0.2 API changes. Because it is not in the public API, this can be done in a following change. Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
30 lines
479 B
Rust
30 lines
479 B
Rust
#![warn(rust_2018_idioms)]
|
|
|
|
use tokio::time::{delay_until, Duration, Instant};
|
|
use tokio_test::block_on;
|
|
|
|
#[test]
|
|
fn async_block() {
|
|
assert_eq!(4, block_on(async { 4 }));
|
|
}
|
|
|
|
async fn five() -> u8 {
|
|
5
|
|
}
|
|
|
|
#[test]
|
|
fn async_fn() {
|
|
assert_eq!(5, block_on(five()));
|
|
}
|
|
|
|
#[test]
|
|
fn test_delay() {
|
|
let deadline = Instant::now() + Duration::from_millis(100);
|
|
assert_eq!(
|
|
(),
|
|
block_on(async {
|
|
delay_until(deadline).await;
|
|
})
|
|
);
|
|
}
|