/// Initiates a lookup stream and obtains the first profile from it.
///
/// If the call fails, recovery and back-off are applied.
Initiates a lookup stream and obtains the first profile from it.
If the call fails, recovery and back-off are applied.
Initiates a lookup stream and obtains the first profile from it . If the call fails recovery and back - off are applied .
async fn init<T, U>(
        &mut self,
        target: &T,
        mut backoff: Option<R::Backoff>,
    ) -> Result<(U, InnerRsp<U>)>
    where
        T: Clone + Send + Sync + 'static,
        S: Service<T, Response = InnerRsp<U>, Error = tonic::Status>,
        S::Future: Send,
    {
        loop {
            trace!("Awaiting readiness");
            let status = match self.inner.ready().await {
                Ok(svc) => {
                    trace!("Issuing request");
                    match svc.call(target.clone()).await {
                        Ok(mut rsp) => match Self::next(rsp.get_mut()).await {
                            Ok(init) => return Ok((init, rsp)),
                            Err(status) => {
                                debug!(%status, "Stream failed");
                                status
                            }
                        },
                        Err(status) => {
                            debug!(%status, "Request failed");
                            status
                        }
                    }
                }
                Err(status) => {
                    debug!(%status, "Service did not become ready");
                    status
                }
            };
            let mut new_backoff = self.recover.recover(status)?;
            debug!("Recovering");
            let use_new_backoff = if let Some(b) = backoff.as_mut() {
                // If there's a already a backoff, wait for it; but if the stream ends, then the
                // newly-obtained backoff is used.
                trace!("Using old backoff");
                b.next().await.is_none()
            } else {
                true
            };
            if use_new_backoff {
                trace!("Using new backoff");
                backoff = new_backoff.next().await.map(move |()| new_backoff);
            }
            trace!("Backed off");
        }
    }
async fn init < T , U > ( & mut self , target : & T , mut backoff : Option < R :: Backoff > , ) -> Result < ( U , InnerRsp < U > ) > where T : Clone + Send + Sync + ' static , S : Service < T , Response = InnerRsp < U > , Error = tonic :: Status > , S :: Future : Send , { loop { trace ! ( " " ) ; let status = match self . inner . ready ( ) . await { Ok ( svc ) => { trace ! ( " " ) ; match svc . call ( target . clone ( ) ) . await { Ok ( mut rsp ) => match Self :: next ( rsp . get_mut ( ) ) . await { Ok ( init ) => return Ok ( ( init , rsp ) ) , Err ( status ) => { debug ! ( status " " ) ; status } } , Err ( status ) => { debug ! ( status " " ) ; status } } } Err ( status ) => { debug ! ( status " " ) ; status } } ; let mut new_backoff = self . recover . recover ( status ) ? ; debug ! ( " " ) ; let use_new_backoff = if let Some ( b ) = backoff . as_mut ( ) { // If there's a already a backoff, wait for it; but if the stream ends, then the // newly-obtained backoff is used. trace ! ( " " ) ; b . next ( ) . await . is_none ( ) } else { true } ; if use_new_backoff { trace ! ( " " ) ; backoff = new_backoff . next ( ) . await . map ( move | ( ) | new_backoff ) ; } trace ! ( " " ) ; } }
Initiates a lookup stream and obtains the first profile from it.
Initiates a lookup stream and obtains the first profile from it .
&mut self
target
&T
backoff
Option<R::Backoff>