I am trying to send a request to a server with data using hyper client. The way I am doing it is
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://localhost:8000".parse().unwrap();
client.get(uri).map_err(|_err| ()).and_then(|resp| {
println!("Never prints out");
tx.send(resp).unwrap();
Ok(())
}).or_else(|_err| {
Err(())
})
});
rx.wait()
}
But send_request
never returns because client.get(url).and_then(...)
is never resolved (found out through print debugging).
The examples on Hyper site call core.run(work)
at the end to get the response. But I really can't use Core
here because it cannot be shared across multiple threads. Is there any other way I can get the client.get(uri).and_then(...)
future to run to completion?