title: Why is my Future implementation blocked after it is polled once and NotReady?
body: <p>I implemented the future and made a request of it, but it blocked my <code>curl</code> and the log shows that <code>poll</code> was only invoked once.</p>
  
  <p>Did I implement anything wrong?</p>
  
  <pre><code>use failure::{format_err, Error};
  use futures::{future, Async};
  use hyper::rt::Future;
  use hyper::service::{service_fn, service_fn_ok};
  use hyper::{Body, Method, Request, Response, Server, StatusCode};
  use log::{debug, error, info};
  use std::{
      sync::{Arc, Mutex},
      task::Waker,
      thread,
  };
  
  pub struct TimerFuture {
      shared_state: Arc&lt;Mutex&lt;SharedState&gt;&gt;,
  }
  
  struct SharedState {
      completed: bool,
      resp: String,
  }
  
  impl Future for TimerFuture {
      type Item = Response&lt;Body&gt;;
      type Error = hyper::Error;
      fn poll(&amp;mut self) -&gt; futures::Poll&lt;Response&lt;Body&gt;, hyper::Error&gt; {
          let mut shared_state = self.shared_state.lock().unwrap();
          if shared_state.completed {
              return Ok(Async::Ready(Response::new(Body::from(
                  shared_state.resp.clone(),
              ))));
          } else {
              return Ok(Async::NotReady);
          }
      }
  }
  
  impl TimerFuture {
      pub fn new(instance: String) -&gt; Self {
          let shared_state = Arc::new(Mutex::new(SharedState {
              completed: false,
              resp: String::new(),
          }));
          let thread_shared_state = shared_state.clone();
          thread::spawn(move || {
              let res = match request_health(instance) {
                  Ok(status) =&gt; status.clone(),
                  Err(err) =&gt; {
                      error!("{:?}", err);
                      format!("{}", err)
                  }
              };
              let mut shared_state = thread_shared_state.lock().unwrap();
              shared_state.completed = true;
              shared_state.resp = res;
          });
  
          TimerFuture { shared_state }
      }
  }
  
  fn request_health(instance_name: String) -&gt; Result&lt;String, Error&gt; {
      std::thread::sleep(std::time::Duration::from_secs(1));
      Ok("health".to_string())
  }
  
  type BoxFut = Box&lt;dyn Future&lt;Item = Response&lt;Body&gt;, Error = hyper::Error&gt; + Send&gt;;
  fn serve_health(req: Request&lt;Body&gt;) -&gt; BoxFut {
      let mut response = Response::new(Body::empty());
      let path = req.uri().path().to_owned();
      match (req.method(), path) {
          (&amp;Method::GET, path) =&gt; {
              return Box::new(TimerFuture::new(path.clone()));
          }
          _ =&gt; *response.status_mut() = StatusCode::NOT_FOUND,
      }
      Box::new(future::ok(response))
  }
  
  fn main() {
      let endpoint_addr = "0.0.0.0:8080";
      match std::thread::spawn(move || {
          let addr = endpoint_addr.parse().unwrap();
          info!("Server is running on {}", addr);
          hyper::rt::run(
              Server::bind(&amp;addr)
                  .serve(move || service_fn(serve_health))
                  .map_err(|e| eprintln!("server error: {}", e)),
          );
      })
      .join()
      {
          Ok(e) =&gt; e,
          Err(e) =&gt; println!("{:?}", e),
      }
  }
  </code></pre>
  
  <p>After compile and run this code, a server with port 8080 is running. Call the server with <code>curl</code> and it will block:</p>
  
  <pre class="lang-none prettyprint-override"><code>curl 127.0.0.1:8080/my-health-scope
  </code></pre>