-
-
Save yjh0502/8dfe143aeb1dccb5f077d31884816aaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate futures; | |
extern crate tokio_core; | |
extern crate hyper; | |
use futures::*; | |
use tokio_core::reactor::*; | |
use hyper::Client; | |
fn send_request(remote: Remote) -> Result<hyper::Response, futures::Canceled> { | |
let (tx, rx) = futures::oneshot(); | |
remote.spawn(|handle| { | |
let client = Client::new(&handle); | |
let uri = "http://rust-lang.org".parse().unwrap(); | |
client | |
.get(uri) | |
.map_err(|_err| ()) | |
.and_then(|resp| { | |
println!("resp: {}", resp.version()); | |
tx.send(resp).unwrap(); | |
Ok(()) | |
}) | |
.or_else(|_err| Err(())) | |
}); | |
rx.wait() | |
} | |
fn main() { | |
let mut core = Core::new().unwrap(); | |
let handle = core.handle(); | |
let remote = handle.remote().clone(); | |
std::thread::spawn(move || send_request(remote)); | |
loop { | |
core.turn(None) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment