pub async fn receive(&mut self) -> Result<TsxResponse> {
        let inner = if let Some(inner) = &mut self.inner {
            inner
        } else {
            // TODO: This is not a nice API :/
            panic!("transaction already received a final response");
        };

        let registration = &mut inner.registration;

        match self.state {
            State::Init if !inner.request.parts.transport.reliable() => {
                loop {
                    let receive = timeout(T2, registration.receive_response());

                    match timeout_at(self.timeout.into(), receive).await {
                        Ok(Ok(msg)) => return self.handle_msg(msg),
                        Ok(Err(_)) => {
                            // retransmit
                            registration
                                .endpoint
                                .send_outgoing_request(&mut inner.request)
                                .await?;
                        }
                        Err(_) => bail_status!(Code::REQUEST_TIMEOUT),
                    }
                }
            }
            State::Init | State::Proceeding => {
                match timeout_at(self.timeout.into(), registration.receive_response()).await {
                    Ok(msg) => self.handle_msg(msg),
                    Err(_) => bail_status!(Code::REQUEST_TIMEOUT),
                }
            }
            State::Completed | State::Terminated => {
                panic!("transaction already received a final response");
            }
        }
    }
/// Receive one or more responses
///
/// Must be called until a final response or error is returned.
///
/// # Panics
/// After receiving the final response this function will panic if called again.
/// This is due to it needing to move out some internal state to a new task.
Receive one or more responses
Must be called until a final response or error is returned.
Receive one or more responses Must be called until a final response or error is returned .
pub async fn receive(&mut self) -> Result<TsxResponse> {
        let inner = if let Some(inner) = &mut self.inner {
            inner
        } else {
            // TODO: This is not a nice API :/
            panic!("transaction already received a final response");
        };
        let registration = &mut inner.registration;
        match self.state {
            State::Init if !inner.request.parts.transport.reliable() => {
                loop {
                    let receive = timeout(T2, registration.receive_response());
                    match timeout_at(self.timeout.into(), receive).await {
                        Ok(Ok(msg)) => return self.handle_msg(msg),
                        Ok(Err(_)) => {
                            // retransmit
                            registration
                                .endpoint
                                .send_outgoing_request(&mut inner.request)
                                .await?;
                        }
                        Err(_) => bail_status!(Code::REQUEST_TIMEOUT),
                    }
                }
            }
            State::Init | State::Proceeding => {
                match timeout_at(self.timeout.into(), registration.receive_response()).await {
                    Ok(msg) => self.handle_msg(msg),
                    Err(_) => bail_status!(Code::REQUEST_TIMEOUT),
                }
            }
            State::Completed | State::Terminated => {
                panic!("transaction already received a final response");
            }
        }
    }
pub async fn receive ( & mut self ) -> Result < TsxResponse > { let inner = if let Some ( inner ) = & mut self . inner { inner } else { // TODO: This is not a nice API :/ panic ! ( " " ) ; } ; let registration = & mut inner . registration ; match self . state { State :: Init if ! inner . request . parts . transport . reliable ( ) => { loop { let receive = timeout ( T2 , registration . receive_response ( ) ) ; match timeout_at ( self . timeout . into ( ) , receive ) . await { Ok ( Ok ( msg ) ) => return self . handle_msg ( msg ) , Ok ( Err ( _ ) ) => { // retransmit registration . endpoint . send_outgoing_request ( & mut inner . request ) . await ? ; } Err ( _ ) => bail_status ! ( Code REQUEST_TIMEOUT ) , } } } State :: Init | State :: Proceeding => { match timeout_at ( self . timeout . into ( ) , registration . receive_response ( ) ) . await { Ok ( msg ) => self . handle_msg ( msg ) , Err ( _ ) => bail_status ! ( Code REQUEST_TIMEOUT ) , } } State :: Completed | State :: Terminated => { panic ! ( " " ) ; } } }
Receive one or more responses
Must be called until a final response or error is returned.
Receive one or more responses Must be called until a final response or error is returned .
&mut self
panics
After receiving the final response this function will panic if called again.
This is due to it needing to move out some internal state to a new task.
After receiving the final response this function will panic if called again . This is due to it needing to move out some internal state to a new task .