time: rename tokio::timer -> tokio::time (#1745)

This commit is contained in:
Carl Lerche
2019-11-06 23:53:46 -08:00
committed by GitHub
parent 4dbe6af0a1
commit 7e35922a1d
42 changed files with 101 additions and 124 deletions
+6 -7
View File
@@ -1,10 +1,9 @@
//! A mocked clock for use with `tokio::timer` based futures. //! A mocked clock for use with `tokio::time` based futures.
//! //!
//! # Example //! # Example
//! //!
//! ``` //! ```
//! use tokio::clock; //! use tokio::time::{clock, delay};
//! use tokio::timer::delay;
//! use tokio_test::{assert_ready, assert_pending, task}; //! use tokio_test::{assert_ready, assert_pending, task};
//! //!
//! use std::time::Duration; //! use std::time::Duration;
@@ -23,8 +22,8 @@
//! ``` //! ```
use tokio::runtime::{Park, Unpark}; use tokio::runtime::{Park, Unpark};
use tokio::timer::clock::{Clock, Now}; use tokio::time::clock::{Clock, Now};
use tokio::timer::Timer; use tokio::time::Timer;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::rc::Rc; use std::rc::Rc;
@@ -125,13 +124,13 @@ impl MockClock {
where where
F: FnOnce(&mut Handle) -> R, F: FnOnce(&mut Handle) -> R,
{ {
tokio::timer::clock::with_default(&self.clock, || { tokio::time::clock::with_default(&self.clock, || {
let park = self.time.mock_park(); let park = self.time.mock_park();
let timer = Timer::new(park); let timer = Timer::new(park);
let handle = timer.handle(); let handle = timer.handle();
let time = self.time.clone(); let time = self.time.clone();
let _timer = tokio::timer::set_default(&handle); let _timer = tokio::time::set_default(&handle);
let mut handle = Handle::new(timer, time); let mut handle = Handle::new(timer, time);
f(&mut handle) f(&mut handle)
// lazy(|| Ok::<_, ()>(f(&mut handle))).wait().unwrap() // lazy(|| Ok::<_, ()>(f(&mut handle))).wait().unwrap()
+1 -1
View File
@@ -18,7 +18,7 @@
use tokio::io::{AsyncRead, AsyncWrite}; use tokio::io::{AsyncRead, AsyncWrite};
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tokio::timer::{clock, timer, Delay}; use tokio::time::{clock, timer, Delay};
use bytes::Buf; use bytes::Buf;
use futures_core::ready; use futures_core::ready;
+1 -1
View File
@@ -1,6 +1,6 @@
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]
use tokio::timer::delay; use tokio::time::delay;
use tokio_test::block_on; use tokio_test::block_on;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
+1 -1
View File
@@ -1,6 +1,6 @@
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]
use tokio::timer::delay; use tokio::time::delay;
use tokio_test::clock::MockClock; use tokio_test::clock::MockClock;
use tokio_test::task; use tokio_test::task;
use tokio_test::{assert_pending, assert_ready}; use tokio_test::{assert_pending, assert_ready};
+4 -4
View File
@@ -33,7 +33,7 @@ default = [
"rt-full", "rt-full",
"signal", "signal",
"sync", "sync",
"timer", "time",
] ]
executor-core = [] executor-core = []
@@ -47,7 +47,7 @@ net-full = ["tcp", "udp", "uds"]
net-driver = ["io-traits", "mio", "blocking", "lazy_static"] net-driver = ["io-traits", "mio", "blocking", "lazy_static"]
rt-current-thread = [ rt-current-thread = [
"executor-core", "executor-core",
"timer", "time",
"sync", "sync",
"net-driver", "net-driver",
] ]
@@ -58,7 +58,7 @@ rt-full = [
"net-full", "net-full",
"rt-current-thread", "rt-current-thread",
"sync", "sync",
"timer", "time",
] ]
signal = [ signal = [
"lazy_static", "lazy_static",
@@ -71,7 +71,7 @@ signal = [
] ]
sync = ["fnv"] sync = ["fnv"]
tcp = ["io", "net-driver"] tcp = ["io", "net-driver"]
timer = ["executor-core", "sync", "slab"] time = ["executor-core", "sync", "slab"]
udp = ["io", "net-driver"] udp = ["io", "net-driver"]
uds = ["io", "net-driver", "mio-uds", "libc"] uds = ["io", "net-driver", "mio-uds", "libc"]
process = [ process = [
-14
View File
@@ -1,14 +0,0 @@
//! A configurable source of time.
//!
//! This module provides the [`now`][n] function, which returns an `Instant`
//! representing "now". The source of time used by this function is configurable
//! and allows mocking out the source of time in tests or performing caching
//! operations to reduce the number of syscalls.
//!
//! Note that, because the source of time is configurable, it is possible to
//! observe non-monotonic behavior when calling [`now`][n] from different
//! executors.
//!
//! [n]: fn.now.html
pub use crate::timer::clock::now;
+4 -4
View File
@@ -1,9 +1,9 @@
//! Asynchronous values. //! Asynchronous values.
#[cfg(feature = "timer")] #[cfg(feature = "time")]
use crate::timer::Timeout; use crate::time::Timeout;
#[cfg(feature = "timer")] #[cfg(feature = "time")]
use std::time::Duration; use std::time::Duration;
#[doc(inline)] #[doc(inline)]
@@ -57,7 +57,7 @@ pub trait FutureExt: Future {
/// } /// }
/// # } /// # }
/// ``` /// ```
#[cfg(feature = "timer")] #[cfg(feature = "time")]
fn timeout(self, timeout: Duration) -> Timeout<Self> fn timeout(self, timeout: Duration) -> Timeout<Self>
where where
Self: Sized, Self: Sized,
+2 -5
View File
@@ -85,9 +85,6 @@ macro_rules! thread_local {
($($tts:tt)+) => { loom::thread_local!{ $($tts)+ } } ($($tts:tt)+) => { loom::thread_local!{ $($tts)+ } }
} }
#[cfg(feature = "timer")]
pub mod clock;
#[cfg(feature = "fs")] #[cfg(feature = "fs")]
pub mod fs; pub mod fs;
@@ -117,8 +114,8 @@ pub mod stream;
#[cfg(feature = "sync")] #[cfg(feature = "sync")]
pub mod sync; pub mod sync;
#[cfg(feature = "timer")] #[cfg(feature = "time")]
pub mod timer; pub mod time;
#[cfg(feature = "rt-full")] #[cfg(feature = "rt-full")]
mod util; mod util;
+2 -2
View File
@@ -22,7 +22,7 @@ use std::fmt;
/// ///
/// ``` /// ```
/// use tokio::runtime::Builder; /// use tokio::runtime::Builder;
/// use tokio::timer::clock::Clock; /// use tokio::time::clock::Clock;
/// ///
/// fn main() { /// fn main() {
/// // build Runtime /// // build Runtime
@@ -324,7 +324,7 @@ impl Builder {
#[cfg(feature = "rt-full")] #[cfg(feature = "rt-full")]
fn build_threadpool(&mut self) -> io::Result<Runtime> { fn build_threadpool(&mut self) -> io::Result<Runtime> {
use crate::runtime::{Kind, ThreadPool}; use crate::runtime::{Kind, ThreadPool};
use crate::timer::clock; use crate::time::clock;
use std::sync::Mutex; use std::sync::Mutex;
let mut net_handles = Vec::new(); let mut net_handles = Vec::new();
+3 -3
View File
@@ -1,9 +1,9 @@
pub(crate) use self::variant::*; pub(crate) use self::variant::*;
#[cfg(feature = "timer")] #[cfg(feature = "time")]
mod variant { mod variant {
use crate::runtime::io; use crate::runtime::io;
use crate::timer::{clock, timer}; use crate::time::{clock, timer};
pub(crate) type Clock = clock::Clock; pub(crate) type Clock = clock::Clock;
pub(crate) type Driver = timer::Timer<io::Driver>; pub(crate) type Driver = timer::Timer<io::Driver>;
@@ -23,7 +23,7 @@ mod variant {
} }
} }
#[cfg(not(feature = "timer"))] #[cfg(not(feature = "time"))]
mod variant { mod variant {
use crate::runtime::io; use crate::runtime::io;
+5 -5
View File
@@ -1,10 +1,10 @@
//! A sequence of asynchronous values. //! A sequence of asynchronous values.
#[cfg(feature = "timer")] #[cfg(feature = "time")]
use std::time::Duration; use std::time::Duration;
#[cfg(feature = "timer")] #[cfg(feature = "time")]
use crate::timer::{throttle::Throttle, Timeout}; use crate::time::{throttle::Throttle, Timeout};
#[doc(inline)] #[doc(inline)]
pub use futures_core::Stream; pub use futures_core::Stream;
@@ -29,7 +29,7 @@ pub trait StreamExt: Stream {
/// Throttle down the stream by enforcing a fixed delay between items. /// Throttle down the stream by enforcing a fixed delay between items.
/// ///
/// Errors are also delayed. /// Errors are also delayed.
#[cfg(feature = "timer")] #[cfg(feature = "time")]
fn throttle(self, duration: Duration) -> Throttle<Self> fn throttle(self, duration: Duration) -> Throttle<Self>
where where
Self: Sized, Self: Sized,
@@ -66,7 +66,7 @@ pub trait StreamExt: Stream {
/// } /// }
/// # } /// # }
/// ``` /// ```
#[cfg(feature = "timer")] #[cfg(feature = "time")]
fn timeout(self, timeout: Duration) -> Timeout<Self> fn timeout(self, timeout: Duration) -> Timeout<Self>
where where
Self: Sized, Self: Sized,
@@ -56,7 +56,7 @@ thread_local! {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # use tokio::timer::clock; /// # use tokio::time::clock;
/// let now = clock::now(); /// let now = clock::now();
/// ``` /// ```
pub fn now() -> Instant { pub fn now() -> Instant {
@@ -1,4 +1,4 @@
use crate::timer::timer::{HandlePriv, Registration}; use crate::time::timer::{HandlePriv, Registration};
use futures_core::ready; use futures_core::ready;
use std::future::Future; use std::future::Future;
@@ -4,10 +4,10 @@
//! //!
//! [`DelayQueue`]: struct.DelayQueue.html //! [`DelayQueue`]: struct.DelayQueue.html
use crate::timer::clock::now; use crate::time::clock::now;
use crate::timer::timer::Handle; use crate::time::timer::Handle;
use crate::timer::wheel::{self, Wheel}; use crate::time::wheel::{self, Wheel};
use crate::timer::{Delay, Error}; use crate::time::{Delay, Error};
use futures_core::ready; use futures_core::ready;
use slab::Slab; use slab::Slab;
@@ -70,7 +70,7 @@ use std::time::{Duration, Instant};
/// Using `DelayQueue` to manage cache entries. /// Using `DelayQueue` to manage cache entries.
/// ///
/// ```rust,no_run /// ```rust,no_run
/// use tokio::timer::{delay_queue, DelayQueue, Error}; /// use tokio::time::{delay_queue, DelayQueue, Error};
/// ///
/// use futures_core::ready; /// use futures_core::ready;
/// use std::collections::HashMap; /// use std::collections::HashMap;
@@ -217,7 +217,7 @@ impl<T> DelayQueue<T> {
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust
/// # use tokio::timer::DelayQueue; /// # use tokio::time::DelayQueue;
/// let delay_queue: DelayQueue<u32> = DelayQueue::new(); /// let delay_queue: DelayQueue<u32> = DelayQueue::new();
/// ``` /// ```
pub fn new() -> DelayQueue<T> { pub fn new() -> DelayQueue<T> {
@@ -231,8 +231,8 @@ impl<T> DelayQueue<T> {
/// # Examples /// # Examples
/// ///
/// ```rust,no_run /// ```rust,no_run
/// # use tokio::timer::DelayQueue; /// # use tokio::time::DelayQueue;
/// use tokio::timer::timer::Handle; /// use tokio::time::timer::Handle;
/// ///
/// let handle = Handle::default(); /// let handle = Handle::default();
/// let delay_queue: DelayQueue<u32> = DelayQueue::with_capacity_and_handle(0, &handle); /// let delay_queue: DelayQueue<u32> = DelayQueue::with_capacity_and_handle(0, &handle);
@@ -258,7 +258,7 @@ impl<T> DelayQueue<T> {
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust
/// # use tokio::timer::DelayQueue; /// # use tokio::time::DelayQueue;
/// # use std::time::Duration; /// # use std::time::Duration;
/// let mut delay_queue = DelayQueue::with_capacity(10); /// let mut delay_queue = DelayQueue::with_capacity(10);
/// ///
@@ -302,7 +302,7 @@ impl<T> DelayQueue<T> {
/// Basic usage /// Basic usage
/// ///
/// ```rust /// ```rust
/// use tokio::timer::DelayQueue; /// use tokio::time::DelayQueue;
/// use std::time::{Instant, Duration}; /// use std::time::{Instant, Duration};
/// ///
/// let mut delay_queue = DelayQueue::new(); /// let mut delay_queue = DelayQueue::new();
@@ -403,7 +403,7 @@ impl<T> DelayQueue<T> {
/// Basic usage /// Basic usage
/// ///
/// ```rust /// ```rust
/// use tokio::timer::DelayQueue; /// use tokio::time::DelayQueue;
/// use std::time::Duration; /// use std::time::Duration;
/// ///
/// let mut delay_queue = DelayQueue::new(); /// let mut delay_queue = DelayQueue::new();
@@ -453,7 +453,7 @@ impl<T> DelayQueue<T> {
/// Basic usage /// Basic usage
/// ///
/// ```rust /// ```rust
/// use tokio::timer::DelayQueue; /// use tokio::time::DelayQueue;
/// use std::time::Duration; /// use std::time::Duration;
/// ///
/// let mut delay_queue = DelayQueue::new(); /// let mut delay_queue = DelayQueue::new();
@@ -464,7 +464,7 @@ impl<T> DelayQueue<T> {
/// assert_eq!(*item.get_ref(), "foo"); /// assert_eq!(*item.get_ref(), "foo");
/// ``` /// ```
pub fn remove(&mut self, key: &Key) -> Expired<T> { pub fn remove(&mut self, key: &Key) -> Expired<T> {
use crate::timer::wheel::Stack; use crate::time::wheel::Stack;
// Special case the `expired` queue // Special case the `expired` queue
if self.slab[key.index].expired { if self.slab[key.index].expired {
@@ -501,7 +501,7 @@ impl<T> DelayQueue<T> {
/// Basic usage /// Basic usage
/// ///
/// ```rust /// ```rust
/// use tokio::timer::DelayQueue; /// use tokio::time::DelayQueue;
/// use std::time::{Duration, Instant}; /// use std::time::{Duration, Instant};
/// ///
/// let mut delay_queue = DelayQueue::new(); /// let mut delay_queue = DelayQueue::new();
@@ -555,7 +555,7 @@ impl<T> DelayQueue<T> {
/// Basic usage /// Basic usage
/// ///
/// ```rust /// ```rust
/// use tokio::timer::DelayQueue; /// use tokio::time::DelayQueue;
/// use std::time::Duration; /// use std::time::Duration;
/// ///
/// let mut delay_queue = DelayQueue::new(); /// let mut delay_queue = DelayQueue::new();
@@ -582,7 +582,7 @@ impl<T> DelayQueue<T> {
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust
/// use tokio::timer::DelayQueue; /// use tokio::time::DelayQueue;
/// use std::time::Duration; /// use std::time::Duration;
/// ///
/// let mut delay_queue = DelayQueue::new(); /// let mut delay_queue = DelayQueue::new();
@@ -607,7 +607,7 @@ impl<T> DelayQueue<T> {
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust
/// use tokio::timer::DelayQueue; /// use tokio::time::DelayQueue;
/// ///
/// let delay_queue: DelayQueue<i32> = DelayQueue::with_capacity(10); /// let delay_queue: DelayQueue<i32> = DelayQueue::with_capacity(10);
/// assert_eq!(delay_queue.capacity(), 10); /// assert_eq!(delay_queue.capacity(), 10);
@@ -636,7 +636,7 @@ impl<T> DelayQueue<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use tokio::timer::DelayQueue; /// use tokio::time::DelayQueue;
/// use std::time::Duration; /// use std::time::Duration;
/// ///
/// let mut delay_queue = DelayQueue::new(); /// let mut delay_queue = DelayQueue::new();
@@ -658,7 +658,7 @@ impl<T> DelayQueue<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use tokio::timer::DelayQueue; /// use tokio::time::DelayQueue;
/// use std::time::Duration; /// use std::time::Duration;
/// ///
/// let mut delay_queue = DelayQueue::new(); /// let mut delay_queue = DelayQueue::new();
@@ -690,8 +690,7 @@ impl<T> DelayQueue<T> {
ready!(Pin::new(&mut *delay).poll(cx)); ready!(Pin::new(&mut *delay).poll(cx));
} }
let now = let now = crate::time::ms(delay.deadline() - self.start, crate::time::Round::Down);
crate::timer::ms(delay.deadline() - self.start, crate::timer::Round::Down);
self.poll = wheel::Poll::new(now); self.poll = wheel::Poll::new(now);
} }
@@ -714,7 +713,7 @@ impl<T> DelayQueue<T> {
let when = if when < self.start { let when = if when < self.start {
0 0
} else { } else {
crate::timer::ms(when - self.start, crate::timer::Round::Up) crate::time::ms(when - self.start, crate::time::Round::Up)
}; };
cmp::max(when, self.wheel.elapsed()) cmp::max(when, self.wheel.elapsed())
@@ -1,4 +1,4 @@
use crate::timer::{clock, Delay}; use crate::time::{clock, Delay};
use futures_core::ready; use futures_core::ready;
use futures_util::future::poll_fn; use futures_util::future::poll_fn;
@@ -39,7 +39,7 @@ impl Interval {
/// Creates new `Interval` that yields with interval of `duration`. /// Creates new `Interval` that yields with interval of `duration`.
/// ///
/// The function is shortcut for `Interval::new(tokio::timer::clock::now() + duration, duration)`. /// The function is shortcut for `Interval::new(tokio::time::clock::now() + duration, duration)`.
/// ///
/// The `duration` argument must be a non-zero duration. /// The `duration` argument must be a non-zero duration.
/// ///
@@ -76,7 +76,7 @@ impl Interval {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use tokio::timer::Interval; /// use tokio::time::Interval;
/// ///
/// use std::time::Duration; /// use std::time::Duration;
/// ///
@@ -21,16 +21,14 @@
//! involving time. //! involving time.
//! //!
//! These types must be used from within the context of the //! These types must be used from within the context of the
//! [`Runtime`][runtime] or a timer context must be setup explicitly. See the //! [`Runtime`][runtime].
//! [`tokio-timer`][tokio-timer] crate for more details on how to setup a timer
//! context.
//! //!
//! # Examples //! # Examples
//! //!
//! Wait 100ms and print "Hello World!" //! Wait 100ms and print "Hello World!"
//! //!
//! ``` //! ```
//! use tokio::timer::delay_for; //! use tokio::time::delay_for;
//! //!
//! use std::time::Duration; //! use std::time::Duration;
//! //!
@@ -66,7 +64,6 @@
//! ``` //! ```
//! //!
//! [runtime]: ../runtime/struct.Runtime.html //! [runtime]: ../runtime/struct.Runtime.html
//! [tokio-timer]: https://docs.rs/tokio-timer
//! [ext]: ../util/trait.FutureExt.html#method.timeout //! [ext]: ../util/trait.FutureExt.html#method.timeout
//! [Timeout]: struct.Timeout.html //! [Timeout]: struct.Timeout.html
//! [Delay]: struct.Delay.html //! [Delay]: struct.Delay.html
@@ -82,7 +79,6 @@ pub use self::delay_queue::DelayQueue;
pub mod throttle; pub mod throttle;
// TODO: clean this up // TODO: clean this up
#[allow(clippy::module_inception)]
pub mod timer; pub mod timer;
pub use timer::{set_default, Timer}; pub use timer::{set_default, Timer};
@@ -112,7 +108,7 @@ pub fn delay(deadline: Instant) -> Delay {
/// Create a Future that completes in `duration` from now. /// Create a Future that completes in `duration` from now.
/// ///
/// Equivalent to `delay(tokio::timer::clock::now() + duration)`. Analogous to `std::thread::sleep`. /// Equivalent to `delay(tokio::time::clock::now() + duration)`. Analogous to `std::thread::sleep`.
pub fn delay_for(duration: Duration) -> Delay { pub fn delay_for(duration: Duration) -> Delay {
delay(clock::now() + duration) delay(clock::now() + duration)
} }
@@ -1,6 +1,6 @@
//! Slow down a stream by enforcing a delay between items. //! Slow down a stream by enforcing a delay between items.
use crate::timer::{clock, Delay}; use crate::time::{clock, Delay};
use futures_core::ready; use futures_core::ready;
use futures_core::Stream; use futures_core::Stream;
@@ -4,8 +4,8 @@
//! //!
//! [`Timeout`]: struct.Timeout.html //! [`Timeout`]: struct.Timeout.html
use crate::timer::clock::now; use crate::time::clock::now;
use crate::timer::Delay; use crate::time::Delay;
use futures_core::ready; use futures_core::ready;
use std::fmt; use std::fmt;
@@ -95,7 +95,7 @@ impl<T> Timeout<T> {
/// Create a new `Timeout` set to expire in 10 milliseconds. /// Create a new `Timeout` set to expire in 10 milliseconds.
/// ///
/// ```rust /// ```rust
/// use tokio::timer::Timeout; /// use tokio::time::Timeout;
/// use tokio::sync::oneshot; /// use tokio::sync::oneshot;
/// ///
/// use std::time::Duration; /// use std::time::Duration;
@@ -1,5 +1,5 @@
use super::Entry; use crate::time::timer::Entry;
use crate::timer::Error; use crate::time::Error;
use std::ptr; use std::ptr;
use std::sync::atomic::AtomicPtr; use std::sync::atomic::AtomicPtr;
@@ -1,7 +1,7 @@
use crate::sync::AtomicWaker; use crate::sync::AtomicWaker;
use crate::timer::atomic::AtomicU64; use crate::time::atomic::AtomicU64;
use crate::timer::timer::{HandlePriv, Inner}; use crate::time::timer::{HandlePriv, Inner};
use crate::timer::Error; use crate::time::Error;
use std::cell::UnsafeCell; use std::cell::UnsafeCell;
use std::ptr; use std::ptr;
@@ -1,6 +1,6 @@
use crate::timer::clock::now; use crate::time::clock::now;
use crate::timer::timer::Inner; use crate::time::timer::Inner;
use crate::timer::{Delay, Error, Timeout}; use crate::time::{Delay, Error, Timeout};
use std::cell::RefCell; use std::cell::RefCell;
use std::fmt; use std::fmt;
@@ -42,10 +42,10 @@ mod stack;
use self::stack::Stack; use self::stack::Stack;
use crate::runtime::{Park, Unpark}; use crate::runtime::{Park, Unpark};
use crate::timer::atomic::AtomicU64; use crate::time::atomic::AtomicU64;
use crate::timer::clock::Clock; use crate::time::clock::Clock;
use crate::timer::wheel; use crate::time::wheel;
use crate::timer::Error; use crate::time::Error;
use std::sync::atomic::AtomicUsize; use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::SeqCst; use std::sync::atomic::Ordering::SeqCst;
@@ -257,9 +257,9 @@ where
/// Run timer related logic /// Run timer related logic
fn process(&mut self) { fn process(&mut self) {
let now = crate::timer::ms( let now = crate::time::ms(
self.clock.now() - self.inner.start, self.clock.now() - self.inner.start,
crate::timer::Round::Down, crate::time::Round::Down,
); );
let mut poll = wheel::Poll::new(now); let mut poll = wheel::Poll::new(now);
@@ -311,7 +311,7 @@ where
/// ///
/// Returns `None` if the entry was fired. /// Returns `None` if the entry was fired.
fn add_entry(&mut self, entry: Arc<Entry>, when: u64) { fn add_entry(&mut self, entry: Arc<Entry>, when: u64) {
use crate::timer::wheel::InsertError; use crate::time::wheel::InsertError;
entry.set_when_internal(Some(when)); entry.set_when_internal(Some(when));
@@ -466,7 +466,7 @@ impl Inner {
return 0; return 0;
} }
crate::timer::ms(deadline - self.start, crate::timer::Round::Up) crate::time::ms(deadline - self.start, crate::time::Round::Up)
} }
} }
@@ -1,5 +1,5 @@
use crate::timer::timer::{Entry, HandlePriv}; use crate::time::timer::{Entry, HandlePriv};
use crate::timer::Error; use crate::time::Error;
use std::sync::Arc; use std::sync::Arc;
use std::task::{self, Poll}; use std::task::{self, Poll};
@@ -47,7 +47,7 @@ impl Registration {
// Used by `Timeout<Stream>` // Used by `Timeout<Stream>`
pub(crate) fn reset_timeout(&mut self) { pub(crate) fn reset_timeout(&mut self) {
let deadline = crate::clock::now() + self.entry.time_ref().duration; let deadline = crate::time::clock::now() + self.entry.time_ref().duration;
unsafe { unsafe {
self.entry.time_mut().deadline = deadline; self.entry.time_mut().deadline = deadline;
} }
@@ -1,5 +1,5 @@
use crate::timer::timer::Entry; use crate::time::timer::Entry;
use crate::timer::wheel; use crate::time::wheel;
use std::ptr; use std::ptr;
use std::sync::Arc; use std::sync::Arc;
@@ -1,4 +1,4 @@
use crate::timer::wheel::Stack; use crate::time::wheel::Stack;
use std::fmt; use std::fmt;
+3 -3
View File
@@ -1,15 +1,15 @@
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]
use tokio::runtime; use tokio::runtime;
use tokio::timer::clock::Clock; use tokio::time::clock::Clock;
use tokio::timer::*; use tokio::time::*;
use std::sync::mpsc; use std::sync::mpsc;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
struct MockNow(Instant); struct MockNow(Instant);
impl tokio::timer::clock::Now for MockNow { impl tokio::time::clock::Now for MockNow {
fn now(&self) -> Instant { fn now(&self) -> Instant {
self.0 self.0
} }
+3 -3
View File
@@ -38,7 +38,7 @@ rt_test! {
use tokio::prelude::*; use tokio::prelude::*;
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
use tokio::sync::oneshot; use tokio::sync::oneshot;
use tokio::timer; use tokio::time;
use tokio_test::{assert_err, assert_ok}; use tokio_test::{assert_err, assert_ok};
use futures_util::future::poll_fn; use futures_util::future::poll_fn;
@@ -289,7 +289,7 @@ rt_test! {
let dur = Duration::from_millis(50); let dur = Duration::from_millis(50);
rt.block_on(async move { rt.block_on(async move {
timer::delay_for(dur).await; time::delay_for(dur).await;
}); });
assert!(now.elapsed() >= dur); assert!(now.elapsed() >= dur);
@@ -306,7 +306,7 @@ rt_test! {
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
tokio::spawn(async move { tokio::spawn(async move {
timer::delay_for(dur).await; time::delay_for(dur).await;
assert_ok!(tx.send(())); assert_ok!(tx.send(()));
}); });
+2 -2
View File
@@ -1,7 +1,7 @@
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]
use tokio::timer::clock; use tokio::time::clock;
use tokio::timer::clock::*; use tokio::time::clock::*;
use std::time::Instant; use std::time::Instant;
+2 -2
View File
@@ -1,7 +1,7 @@
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]
use tokio::timer::delay; use tokio::time::delay;
use tokio::timer::timer::Handle; use tokio::time::timer::Handle;
use tokio_test::task; use tokio_test::task;
use tokio_test::{assert_pending, assert_ready, clock}; use tokio_test::{assert_pending, assert_ready, clock};
+1 -1
View File
@@ -3,7 +3,7 @@
use tokio::executor::park::{Park, Unpark, UnparkThread}; use tokio::executor::park::{Park, Unpark, UnparkThread};
use tokio::runtime; use tokio::runtime;
use tokio::timer::{Delay, Timer}; use tokio::time::{Delay, Timer};
use rand::Rng; use rand::Rng;
use std::cmp; use std::cmp;
+1 -1
View File
@@ -1,6 +1,6 @@
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]
use tokio::timer::*; use tokio::time::*;
use tokio_test::task; use tokio_test::task;
use tokio_test::{assert_pending, assert_ready_eq, clock}; use tokio_test::{assert_pending, assert_ready_eq, clock};
+1 -1
View File
@@ -1,6 +1,6 @@
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]
use tokio::timer::*; use tokio::time::*;
use tokio_test::{assert_ok, assert_pending, assert_ready}; use tokio_test::{assert_ok, assert_pending, assert_ready};
use tokio_test::{clock, task}; use tokio_test::{clock, task};
+2 -2
View File
@@ -1,7 +1,7 @@
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]
use tokio::prelude::*; use tokio::prelude::*;
use tokio::timer::*; use tokio::time::*;
use std::sync::mpsc; use std::sync::mpsc;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@@ -35,7 +35,7 @@ fn timer_with_current_thread_runtime() {
rt.block_on(async move { rt.block_on(async move {
let when = Instant::now() + Duration::from_millis(100); let when = Instant::now() + Duration::from_millis(100);
tokio::timer::delay(when).await; tokio::time::delay(when).await;
assert!(Instant::now() >= when); assert!(Instant::now() >= when);
tx.send(()).unwrap(); tx.send(()).unwrap();
+1 -1
View File
@@ -1,7 +1,7 @@
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tokio::timer::throttle::Throttle; use tokio::time::throttle::Throttle;
use tokio_test::task; use tokio_test::task;
use tokio_test::{assert_pending, assert_ready_eq, clock}; use tokio_test::{assert_pending, assert_ready_eq, clock};
+1 -1
View File
@@ -1,7 +1,7 @@
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]
use tokio::sync::oneshot; use tokio::sync::oneshot;
use tokio::timer::*; use tokio::time::*;
use tokio_test::task; use tokio_test::task;
use tokio_test::{ use tokio_test::{
assert_err, assert_pending, assert_ready, assert_ready_err, assert_ready_ok, clock, assert_err, assert_pending, assert_ready, assert_ready_err, assert_ready_ok, clock,