mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-26 00:00:16 +02:00
This patch started as an effort to make `time::Timer` private. However, in an effort to get the build compiling again, more and more changes were made. This probably should have been broken up, but here we are. I will attempt to summarize the changes here. * Feature flags are reorganized to make clearer. `net-driver` becomes `io-driver`. `rt-current-thread` becomes `rt-core`. * The `Runtime` can be created without any executor. This replaces `enter`. It also allows creating I/O / time drivers that are standalone. * `tokio::timer` is renamed to `tokio::time`. This brings it in line with `std`. * `tokio::timer::Timer` is renamed to `Driver` and made private. * The `clock` module is removed. Instead, an `Instant` type is provided. This type defaults to calling `std::time::Instant`. A `test-util` feature flag can be used to enable hooking into time. * The `blocking` module is moved to the top level and is cleaned up. * The `task` module is moved to the top level. * The thread-pool's in-place blocking implementation is cleaned up. * `runtime::Spawner` is renamed to `runtime::Handle` and can be used to "enter" a runtime context.
25 lines
408 B
Rust
25 lines
408 B
Rust
#![warn(rust_2018_idioms)]
|
|
|
|
use tokio::time::{delay, 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(delay(deadline)));
|
|
}
|