Skip to content

Commit 792b55f

Browse files
authored
Merge pull request #1502 from hyperium/tokio-timer
refactor(lib): change from futures-timer to tokio-timer
2 parents 5e3b43a + 7a7453b commit 792b55f

File tree

9 files changed

+248
-228
lines changed

9 files changed

+248
-228
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ cache:
1818
script:
1919
- ./.travis/readme.py
2020
- cargo build $FEATURES
21-
- 'if [ "$BUILD_ONLY" != "1" ]; then RUST_LOG=hyper cargo test $FEATURES; fi'
21+
- 'if [ "$BUILD_ONLY" != "1" ]; then RUST_LOG=hyper cargo test $FEATURES -- --test-threads=1; fi'
2222
- 'if [ $TRAVIS_RUST_VERSION = nightly ]; then for f in ./benches/*.rs; do cargo test --bench $(basename $f .rs) $FEATURES; done; fi'
2323

2424
addons:

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ include = [
2424
bytes = "0.4.4"
2525
futures = "0.1.21"
2626
futures-cpupool = { version = "0.1.6", optional = true }
27-
futures-timer = "0.1.0"
2827
http = "0.1.5"
2928
httparse = "1.0"
3029
h2 = "0.1.5"
@@ -37,9 +36,11 @@ tokio-executor = { version = "0.1.0", optional = true }
3736
tokio-io = "0.1"
3837
tokio-reactor = { version = "0.1", optional = true }
3938
tokio-tcp = { version = "0.1", optional = true }
39+
tokio-timer = { version = "0.2", optional = true }
4040
want = "0.0.4"
4141

4242
[dev-dependencies]
43+
futures-timer = "0.1"
4344
num_cpus = "1.0"
4445
pretty_env_logger = "0.2.0"
4546
spmc = "0.2"
@@ -55,6 +56,7 @@ runtime = [
5556
"tokio-executor",
5657
"tokio-reactor",
5758
"tokio-tcp",
59+
"tokio-timer",
5860
]
5961

6062
[[example]]

src/client/mod.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,6 @@ where C: Connect + Sync + 'static,
113113

114114
/// Send a constructed Request using this Client.
115115
pub fn request(&self, mut req: Request<B>) -> FutureResponse {
116-
// TODO(0.12): do this at construction time.
117-
//
118-
// It cannot be done in the constructor because the Client::configured
119-
// does not have `B: 'static` bounds, which are required to spawn
120-
// the interval. In 0.12, add a static bounds to the constructor,
121-
// and move this.
122-
self.schedule_pool_timer();
123-
124116
match req.version() {
125117
Version::HTTP_10 |
126118
Version::HTTP_11 => (),
@@ -302,7 +294,7 @@ where C: Connect + Sync + 'static,
302294
// for a new request to start.
303295
//
304296
// It won't be ready if there is a body to stream.
305-
if ver == Ver::Http2 || pooled.is_ready() {
297+
if ver == Ver::Http2 || !pooled.is_pool_enabled() || pooled.is_ready() {
306298
drop(pooled);
307299
} else if !res.body().is_empty() {
308300
let (delayed_tx, delayed_rx) = oneshot::channel();
@@ -336,10 +328,6 @@ where C: Connect + Sync + 'static,
336328

337329
Box::new(resp)
338330
}
339-
340-
fn schedule_pool_timer(&self) {
341-
self.pool.spawn_expired_interval(&self.executor);
342-
}
343331
}
344332

345333
impl<C, B> Clone for Client<C, B> {
@@ -474,7 +462,7 @@ impl<B: Payload + 'static> PoolClient<B> {
474462

475463
impl<B> Poolable for PoolClient<B>
476464
where
477-
B: 'static,
465+
B: Send + 'static,
478466
{
479467
fn is_open(&self) -> bool {
480468
match self.tx {
@@ -700,7 +688,7 @@ impl Builder {
700688
executor: self.exec.clone(),
701689
h1_writev: self.h1_writev,
702690
h1_title_case_headers: self.h1_title_case_headers,
703-
pool: Pool::new(self.keep_alive, self.keep_alive_timeout),
691+
pool: Pool::new(self.keep_alive, self.keep_alive_timeout, &self.exec),
704692
retry_canceled_requests: self.retry_canceled_requests,
705693
set_host: self.set_host,
706694
ver: self.ver,

0 commit comments

Comments
 (0)