Skip to content

Commit eb7d787

Browse files
committed
timer: move tokio-timer into tokio crate
A step towards collapsing Tokio sub crates into a single `tokio` crate (#1318). The `timer` implementation is now provided by the main `tokio` crate. The `timer` functionality may still be excluded from the build by skipping the `timer` feature flag.
1 parent ed5a94e commit eb7d787

37 files changed

+184
-236
lines changed

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ members = [
1010
"tokio-net",
1111
"tokio-sync",
1212
"tokio-test",
13-
"tokio-timer",
1413
"tokio-tls",
1514
"build-tests",
1615
]

ci/patch.toml

-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ tokio-io = { path = "tokio-io" }
99
tokio-macros = { path = "tokio-macros" }
1010
tokio-net = { path = "tokio-net" }
1111
tokio-sync = { path = "tokio-sync" }
12-
tokio-timer = { path = "tokio-timer" }
1312
tokio-tls = { path = "tokio-tls" }

tokio-test/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ tokio = { version = "=0.2.0-alpha.6", path = "../tokio" }
2424
tokio-executor = { version = "=0.2.0-alpha.6", path = "../tokio-executor" }
2525
tokio-io = { version = "=0.2.0-alpha.6", path = "../tokio-io" }
2626
tokio-sync = { version = "=0.2.0-alpha.6", path = "../tokio-sync" }
27-
tokio-timer = { version = "=0.3.0-alpha.6", path = "../tokio-timer" }
2827

2928
futures-core-preview = "=0.3.0-alpha.19"
3029
pin-convert = "0.1.0"

tokio-test/src/clock.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
//! });
2323
//! ```
2424
25+
use tokio::timer::clock::{Clock, Now};
26+
use tokio::timer::Timer;
2527
use tokio_executor::park::{Park, Unpark};
26-
use tokio_timer::clock::{Clock, Now};
27-
use tokio_timer::Timer;
2828

2929
use std::marker::PhantomData;
3030
use std::rc::Rc;
@@ -125,13 +125,13 @@ impl MockClock {
125125
where
126126
F: FnOnce(&mut Handle) -> R,
127127
{
128-
::tokio_timer::clock::with_default(&self.clock, || {
128+
tokio::timer::clock::with_default(&self.clock, || {
129129
let park = self.time.mock_park();
130130
let timer = Timer::new(park);
131131
let handle = timer.handle();
132132
let time = self.time.clone();
133133

134-
let _timer = ::tokio_timer::set_default(&handle);
134+
let _timer = tokio::timer::set_default(&handle);
135135
let mut handle = Handle::new(timer, time);
136136
f(&mut handle)
137137
// lazy(|| Ok::<_, ()>(f(&mut handle))).wait().unwrap()

tokio-test/src/io.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
//! [`AsyncRead`]: tokio_io::AsyncRead
1717
//! [`AsyncWrite`]: tokio_io::AsyncWrite
1818
19+
use tokio::timer::{clock, timer, Delay};
20+
use tokio_io::{AsyncRead, AsyncWrite, Buf};
21+
use tokio_sync::mpsc;
22+
23+
use futures_core::ready;
1924
use std::collections::VecDeque;
2025
use std::future::Future;
2126
use std::pin::Pin;
2227
use std::task::{self, Poll, Waker};
2328
use std::time::{Duration, Instant};
2429
use std::{cmp, io};
2530

26-
use futures_core::ready;
27-
use tokio_io::{AsyncRead, AsyncWrite, Buf};
28-
use tokio_sync::mpsc;
29-
use tokio_timer::{clock, timer, Delay};
30-
3131
/// An I/O object that follows a predefined script.
3232
///
3333
/// This value is created by `Builder` and implements `AsyncRead` + `AsyncWrite`. It

tokio-timer/src/lib.rs

-105
This file was deleted.

tokio/Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ rt-full = [
5959
signal = ["tokio-net/signal"]
6060
sync = ["tokio-sync"]
6161
tcp = ["io", "tokio-net/tcp"]
62-
timer = ["tokio-timer"]
62+
timer = ["crossbeam-utils", "slab"]
6363
tracing = ["tracing-core"]
6464
udp = ["io", "tokio-net/udp"]
6565
uds = ["io", "tokio-net/uds"]
@@ -72,15 +72,17 @@ futures-util-preview = { version = "=0.3.0-alpha.19", features = ["sink"] }
7272

7373
# Everything else is optional...
7474
bytes = { version = "0.4", optional = true }
75+
crossbeam-utils = { version = "0.6.0", optional = true }
7576
num_cpus = { version = "1.8.0", optional = true }
77+
# Backs `DelayQueue`
78+
slab = { version = "0.4.1", optional = true }
7679
tokio-codec = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-codec" }
7780
tokio-fs = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-fs" }
7881
tokio-io = { version = "=0.2.0-alpha.6", optional = true, features = ["util"], path = "../tokio-io" }
7982
tokio-executor = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-executor" }
8083
tokio-macros = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-macros" }
8184
tokio-net = { version = "=0.2.0-alpha.6", optional = true, features = ["async-traits"], path = "../tokio-net" }
8285
tokio-sync = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-sync", features = ["async-traits"] }
83-
tokio-timer = { version = "=0.3.0-alpha.6", optional = true, path = "../tokio-timer", features = ["async-traits"] }
8486
tracing-core = { version = "0.1", optional = true }
8587

8688
[target.'cfg(feature = "tracing")'.dependencies]

tokio/src/clock.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
//!
33
//! This module provides the [`now`][n] function, which returns an `Instant`
44
//! representing "now". The source of time used by this function is configurable
5-
//! (via the [`tokio-timer`] crate) and allows mocking out the source of time in
6-
//! tests or performing caching operations to reduce the number of syscalls.
5+
//! and allows mocking out the source of time in tests or performing caching
6+
//! operations to reduce the number of syscalls.
77
//!
88
//! Note that, because the source of time is configurable, it is possible to
99
//! observe non-monotonic behavior when calling [`now`][n] from different
1010
//! executors.
1111
//!
1212
//! [n]: fn.now.html
13-
//! [`tokio-timer`]: https://docs.rs/tokio-timer/0.2/tokio_timer/clock/index.html
1413
15-
pub use tokio_timer::clock::now;
14+
pub use crate::timer::clock::now;

tokio/src/future.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Asynchronous values.
22
33
#[cfg(feature = "timer")]
4-
use tokio_timer::Timeout;
4+
use crate::timer::Timeout;
55

66
#[cfg(feature = "timer")]
77
use std::time::Duration;

tokio/src/runtime/current_thread/builder.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::runtime::current_thread::Runtime;
2+
use crate::timer::clock::Clock;
3+
use crate::timer::timer::Timer;
24

35
use tokio_executor::current_thread::CurrentThread;
46
use tokio_net::driver::Reactor;
5-
use tokio_timer::clock::Clock;
6-
use tokio_timer::timer::Timer;
77

88
use std::io;
99

@@ -24,7 +24,7 @@ use std::io;
2424
///
2525
/// ```
2626
/// use tokio::runtime::current_thread::Builder;
27-
/// use tokio_timer::clock::Clock;
27+
/// use tokio::timer::clock::Clock;
2828
///
2929
/// # pub fn main() {
3030
/// // build Runtime
@@ -66,7 +66,7 @@ impl Builder {
6666

6767
// Place a timer wheel on top of the reactor. If there are no timeouts to fire, it'll let the
6868
// reactor pick up some new external events.
69-
let timer = Timer::new_with_now(reactor, self.clock.clone());
69+
let timer = Timer::new_with_clock(reactor, self.clock.clone());
7070
let timer_handle = timer.handle();
7171

7272
// And now put a single-threaded executor on top of the timer. When there are no futures ready

tokio/src/runtime/current_thread/runtime.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::runtime::current_thread::Builder;
2+
use crate::timer::clock::{self, Clock};
3+
use crate::timer::timer::{self, Timer};
24

35
use tokio_executor::current_thread::Handle as ExecutorHandle;
46
use tokio_executor::current_thread::{self, CurrentThread};
57
use tokio_net::driver::{self, Reactor};
6-
use tokio_timer::clock::{self, Clock};
7-
use tokio_timer::timer::{self, Timer};
88

99
use std::error::Error;
1010
use std::fmt;

tokio/src/runtime/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//!
2121
//! * Spawn a background thread running a [`Reactor`] instance.
2222
//! * Start a [`ThreadPool`] for executing futures.
23-
//! * Run an instance of [`Timer`] **per** thread pool worker thread.
23+
//! * Run an instance of `Timer` **per** thread pool worker thread.
2424
//!
2525
//! The thread pool uses a work-stealing strategy and is configured to start a
2626
//! worker thread for each CPU core available on the system. This tends to be
@@ -127,7 +127,6 @@
127127
//! [`ThreadPool`]: https://docs.rs/tokio-executor/0.2.0-alpha.2/tokio_executor/threadpool/struct.ThreadPool.html
128128
//! [`run`]: fn.run.html
129129
//! [`tokio::spawn`]: ../executor/fn.spawn.html
130-
//! [`Timer`]: https://docs.rs/tokio-timer/0.2/tokio_timer/timer/struct.Timer.html
131130
//! [`tokio::main`]: ../../tokio_macros/attr.main.html
132131
133132
pub mod current_thread;

tokio/src/runtime/threadpool/builder.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use super::{Inner, Runtime};
2+
use crate::timer::clock::{self, Clock};
3+
use crate::timer::timer::{self, Timer};
24

35
use tokio_executor::thread_pool;
46
use tokio_net::driver::{self, Reactor};
5-
use tokio_timer::clock::{self, Clock};
6-
use tokio_timer::timer::{self, Timer};
77

88
use tracing_core as trace;
99
use std::{fmt, io};
@@ -26,7 +26,7 @@ use std::sync::{Arc, Mutex};
2626
///
2727
/// ```
2828
/// use tokio::runtime::Builder;
29-
/// use tokio_timer::clock::Clock;
29+
/// use tokio::timer::clock::Clock;
3030
///
3131
/// fn main() {
3232
/// // build Runtime
@@ -233,7 +233,7 @@ impl Builder {
233233
reactor_handles.push(reactor.handle());
234234

235235
// Create a new timer.
236-
let timer = Timer::new_with_now(reactor, self.clock.clone());
236+
let timer = Timer::new_with_clock(reactor, self.clock.clone());
237237
timer_handles.push(timer.handle());
238238
timers.push(Mutex::new(Some(timer)));
239239
}

tokio/src/runtime/threadpool/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ pub use self::spawner::Spawner;
99
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411
1010
pub use tokio_executor::thread_pool::JoinHandle;
1111

12+
use crate::timer::timer;
13+
1214
use tokio_executor::thread_pool::ThreadPool;
1315
use tokio_net::driver;
14-
use tokio_timer::timer;
1516

1617
use tracing_core as trace;
1718
use std::future::Future;

tokio/src/stream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::time::Duration;
55

66
#[cfg(feature = "timer")]
7-
use tokio_timer::{throttle::Throttle, Timeout};
7+
use crate::timer::{throttle::Throttle, Timeout};
88

99
#[doc(inline)]
1010
pub use futures_core::Stream;
File renamed without changes.

tokio-timer/src/clock/mod.rs tokio/src/timer/clock/mod.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ mod now;
2020

2121
pub use self::now::Now;
2222

23-
use crate::timer;
2423
use std::cell::Cell;
2524
use std::fmt;
2625
use std::sync::Arc;
@@ -57,7 +56,7 @@ thread_local! {
5756
/// # Examples
5857
///
5958
/// ```
60-
/// # use tokio_timer::clock;
59+
/// # use tokio::timer::clock;
6160
/// let now = clock::now();
6261
/// ```
6362
pub fn now() -> Instant {
@@ -102,13 +101,6 @@ impl Clock {
102101
}
103102
}
104103

105-
#[allow(deprecated)]
106-
impl timer::Now for Clock {
107-
fn now(&mut self) -> Instant {
108-
Clock::now(self)
109-
}
110-
}
111-
112104
impl fmt::Debug for Clock {
113105
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
114106
fmt.debug_struct("Clock")
File renamed without changes.
File renamed without changes.

tokio-timer/src/delay.rs tokio/src/timer/delay.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::timer::{HandlePriv, Registration};
1+
use crate::timer::timer::{HandlePriv, Registration};
2+
23
use futures_core::ready;
34
use std::future::Future;
45
use std::pin::Pin;
@@ -78,8 +79,6 @@ impl Delay {
7879
self.registration.reset(deadline);
7980
}
8081

81-
// Used by `Timeout<Stream>`
82-
#[cfg(feature = "async-traits")]
8382
pub(crate) fn reset_timeout(&mut self) {
8483
self.registration.reset_timeout();
8584
}

0 commit comments

Comments
 (0)