summaryrefslogtreecommitdiffstats
path: root/tokio-test
diff options
context:
space:
mode:
authorJakub Beránek <berykubik@gmail.com>2019-08-20 17:39:55 +0200
committerCarl Lerche <me@carllerche.com>2019-08-20 08:39:55 -0700
commit2d56312b89ba407272b161290d563551efc896a6 (patch)
tree5906575cc0e25535a74e287a685beb64f669fff2 /tokio-test
parent357df38861ec61547b5b1d90f0007c11d53fb9ec (diff)
timer: introduce delay function shortcut (#1440)
This commit adds a simple delay shortcut to avoid writing Delay::new everywhere and removes usages of Delay::new.
Diffstat (limited to 'tokio-test')
-rw-r--r--tokio-test/src/clock.rs5
-rw-r--r--tokio-test/tests/block_on.rs8
-rw-r--r--tokio-test/tests/clock.rs6
3 files changed, 8 insertions, 11 deletions
diff --git a/tokio-test/src/clock.rs b/tokio-test/src/clock.rs
index 43f073d9..a5c8b4f2 100644
--- a/tokio-test/src/clock.rs
+++ b/tokio-test/src/clock.rs
@@ -7,14 +7,13 @@
//!
//! use tokio::clock;
//! use tokio_test::{assert_ready, assert_pending, task};
-//! use tokio_timer::Delay;
+//! use tokio_timer::delay;
//!
//! use std::time::Duration;
//!
//! tokio_test::clock::mock(|handle| {
//! let mut task = task::spawn(async {
-//! let delay = Delay::new(clock::now() + Duration::from_secs(1));
-//! delay.await
+//! delay(clock::now() + Duration::from_secs(1)).await
//! });
//!
//! assert_pending!(task.poll());
diff --git a/tokio-test/tests/block_on.rs b/tokio-test/tests/block_on.rs
index 7d56ec62..f0a90d11 100644
--- a/tokio-test/tests/block_on.rs
+++ b/tokio-test/tests/block_on.rs
@@ -3,7 +3,7 @@
use std::time::{Duration, Instant};
use tokio_test::block_on;
-use tokio_timer::Delay;
+use tokio_timer::delay;
#[test]
fn async_block() {
@@ -20,9 +20,7 @@ fn async_fn() {
}
#[test]
-fn delay() {
+fn test_delay() {
let deadline = Instant::now() + Duration::from_millis(100);
- let delay = Delay::new(deadline);
-
- assert_eq!((), block_on(delay));
+ assert_eq!((), block_on(delay(deadline)));
}
diff --git a/tokio-test/tests/clock.rs b/tokio-test/tests/clock.rs
index 915f6899..344c599b 100644
--- a/tokio-test/tests/clock.rs
+++ b/tokio-test/tests/clock.rs
@@ -6,7 +6,7 @@ use std::time::{Duration, Instant};
use tokio_test::clock::MockClock;
use tokio_test::task::MockTask;
use tokio_test::{assert_not_ready, assert_ready};
-use tokio_timer::Delay;
+use tokio_timer::delay;
#[test]
fn clock() {
@@ -14,7 +14,7 @@ fn clock() {
mock.enter(|handle| {
let deadline = Instant::now() + Duration::from_secs(1);
- let mut delay = Delay::new(deadline);
+ let mut delay = delay(deadline);
assert_not_ready!(delay.poll());
@@ -31,7 +31,7 @@ fn notify() {
let mut task = MockTask::new();
mock.enter(|handle| {
- let mut delay = Delay::new(deadline);
+ let mut delay = delay(deadline);
task.enter(|| assert_not_ready!(delay.poll()));