pub fn next(&self) -> BoxFuture<(T, HealthReportToken), String> {
    let now = Instant::now();
    let server_count = self.inner.servers.len();

    let mut earliest_future = None;
    for _ in 0..server_count {
      let i = self.inner.next.fetch_add(1, Ordering::Relaxed) % server_count;
      let server = &self.inner.servers[i];
      let unhealthy_info = server.unhealthy_info.lock();
      if let Some(ref unhealthy_info) = *unhealthy_info {
        // Server is unhealthy. Note when it will become healthy.

        let healthy_at = unhealthy_info.healthy_at();

        if healthy_at > now {
          let healthy_sooner_than_previous = if let Some((_, previous_healthy_at)) = earliest_future
          {
            previous_healthy_at > healthy_at
          } else {
            true
          };

          if healthy_sooner_than_previous {
            earliest_future = Some((i, healthy_at));
          }
          continue;
        }
      }
      // A healthy server! Use it!
      return futures::future::ok((server.server.clone(), HealthReportToken { index: i }))
        .to_boxed();
    }
    // Unwrap is safe because if we hadn't populated earliest_future, we would already have returned.
    let (index, instant) = earliest_future.unwrap();
    let server = self.inner.servers[index].server.clone();
    // Note that Delay::new_at(time in the past) gets immediately scheduled.
    Delay::new_handle(instant, self.inner.timer_handle.clone())
      .map_err(|err| format!("Error delaying for serverset: {}", err))
      .map(move |()| (server, HealthReportToken { index }))
      .to_boxed()
  }
///
/// Get the next (probably) healthy backend to use.
///
/// The caller will be given a backend to use, and should call Serverset::report_health with the
/// supplied token, and the observed health of that backend.
///
/// If report_health is not called, the health status of the server will not be changed from its
/// last known status.
///
/// If all resources are unhealthy, the returned Future will delay until a resource becomes
/// healthy.
///
/// No efforts are currently made to avoid a thundering heard at few healthy servers (or the the
/// first server to become healthy after all are unhealthy).
///
Get the next (probably) healthy backend to use.
The caller will be given a backend to use, and should call Serverset::report_health with the
supplied token, and the observed health of that backend.

If report_health is not called, the health status of the server will not be changed from its
last known status.

If all resources are unhealthy, the returned Future will delay until a resource becomes
healthy.

No efforts are currently made to avoid a thundering heard at few healthy servers (or the the
first server to become healthy after all are unhealthy).
Get the next ( probably ) healthy backend to use . The caller will be given a backend to use and should call Serverset :: report_health with the supplied token and the observed health of that backend . If report_health is not called the health status of the server will not be changed from its last known status . If all resources are unhealthy the returned Future will delay until a resource becomes healthy . No efforts are currently made to avoid a thundering heard at few healthy servers ( or the the first server to become healthy after all are unhealthy ) .
pub fn next(&self) -> BoxFuture<(T, HealthReportToken), String> {
    let now = Instant::now();
    let server_count = self.inner.servers.len();
    let mut earliest_future = None;
    for _ in 0..server_count {
      let i = self.inner.next.fetch_add(1, Ordering::Relaxed) % server_count;
      let server = &self.inner.servers[i];
      let unhealthy_info = server.unhealthy_info.lock();
      if let Some(ref unhealthy_info) = *unhealthy_info {
        // Server is unhealthy. Note when it will become healthy.
        let healthy_at = unhealthy_info.healthy_at();
        if healthy_at > now {
          let healthy_sooner_than_previous = if let Some((_, previous_healthy_at)) = earliest_future
          {
            previous_healthy_at > healthy_at
          } else {
            true
          };
          if healthy_sooner_than_previous {
            earliest_future = Some((i, healthy_at));
          }
          continue;
        }
      }
      // A healthy server! Use it!
      return futures::future::ok((server.server.clone(), HealthReportToken { index: i }))
        .to_boxed();
    }
    // Unwrap is safe because if we hadn't populated earliest_future, we would already have returned.
    let (index, instant) = earliest_future.unwrap();
    let server = self.inner.servers[index].server.clone();
    // Note that Delay::new_at(time in the past) gets immediately scheduled.
    Delay::new_handle(instant, self.inner.timer_handle.clone())
      .map_err(|err| format!("Error delaying for serverset: {}", err))
      .map(move |()| (server, HealthReportToken { index }))
      .to_boxed()
  }
pub fn next ( & self ) -> BoxFuture < ( T , HealthReportToken ) , String > { let now = Instant :: now ( ) ; let server_count = self . inner . servers . len ( ) ; let mut earliest_future = None ; for _ in 0 .. server_count { let i = self . inner . next . fetch_add ( 1 , Ordering :: Relaxed ) % server_count ; let server = & self . inner . servers [ i ] ; let unhealthy_info = server . unhealthy_info . lock ( ) ; if let Some ( ref unhealthy_info ) = * unhealthy_info { // Server is unhealthy. Note when it will become healthy. let healthy_at = unhealthy_info . healthy_at ( ) ; if healthy_at > now { let healthy_sooner_than_previous = if let Some ( ( _ , previous_healthy_at ) ) = earliest_future { previous_healthy_at > healthy_at } else { true } ; if healthy_sooner_than_previous { earliest_future = Some ( ( i , healthy_at ) ) ; } continue ; } } // A healthy server! Use it! return futures :: future :: ok ( ( server . server . clone ( ) , HealthReportToken { index : i } ) ) . to_boxed ( ) ; } // Unwrap is safe because if we hadn't populated earliest_future, we would already have returned. let ( index , instant ) = earliest_future . unwrap ( ) ; let server = self . inner . servers [ index ] . server . clone ( ) ; // Note that Delay::new_at(time in the past) gets immediately scheduled. Delay :: new_handle ( instant , self . inner . timer_handle . clone ( ) ) . map_err ( | err | format ! ( " " err ) ) . map ( move | ( ) | ( server , HealthReportToken { index } ) ) . to_boxed ( ) }
Get the next (probably) healthy backend to use.
Get the next ( probably ) healthy backend to use .
&self
&self