Skip to content

Commit

Permalink
refactor(client): make HttpConnector lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed May 8, 2017
1 parent e6b588b commit 6655134
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/client/connect.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::error::Error as StdError;
use std::fmt;
use std::io;
use std::mem;
//use std::net::SocketAddr;

use futures::{Future, Poll, Async};
Expand Down Expand Up @@ -109,7 +110,7 @@ impl Service for HttpConnector {
};

HttpConnecting {
state: State::Resolving(self.dns.resolve(host.into(), port)),
state: State::Lazy(self.dns.clone(), host.into(), port),
handle: self.handle.clone(),
}
}
Expand Down Expand Up @@ -153,6 +154,7 @@ pub struct HttpConnecting {
}

enum State {
Lazy(dns::Dns, String, u16),
Resolving(dns::Query),
Connecting(ConnectingTcp),
Error(Option<io::Error>),
Expand All @@ -166,6 +168,10 @@ impl Future for HttpConnecting {
loop {
let state;
match self.state {
State::Lazy(ref dns, ref mut host, port) => {
let host = mem::replace(host, String::new());
state = State::Resolving(dns.resolve(host, port));
},
State::Resolving(ref mut query) => {
match try!(query.poll()) {
Async::NotReady => return Ok(Async::NotReady),
Expand Down

0 comments on commit 6655134

Please sign in to comment.