/// Processes the next request in the queue of pending requests.
///
/// If the queue is empty, nothing happens.
///
/// Should only be called on the main task spawned in [SettingProxy::create](#method.create).
Processes the next request in the queue of pending requests.
If the queue is empty, nothing happens.

Should only be called on the main task spawned in [SettingProxy::create](#method.create).
Processes the next request in the queue of pending requests . If the queue is empty nothing happens . Should only be called on the main task spawned in [ SettingProxy :: create ] ( #method . create ) .
async fn execute_next_request(&mut self, recreate_handler: bool) {
        if self.active_request.is_none() {
            // Add the request to the queue of requests to process.
            self.active_request = Some(ActiveRequest {
                request: self
                    .pending_requests
                    .pop_front()
                    .expect("execute should only be called with present requests"),
                attempts: 0,
                last_result: None,
            });
        }
        // Recreating signature is always honored, even if the request is not.
        let signature = self
            .get_handler_signature(recreate_handler)
            .await
            .expect("failed to generate handler signature");
        // since we borrow self as mutable for active_request, we must retrieve
        // the listening state (which borrows immutable) before.
        let was_listening = self.is_listening();
        let active_request =
            self.active_request.as_mut().expect("active request should be present");
        active_request.attempts += 1;
        // Note that we must copy these values as we are borrowing self for
        // active_requests and self is needed to remove active below.
        let request = active_request.get_request();
        if matches!(request, Request::Listen) {
            let info = active_request.get_info();
            // Add a callback when the client side goes out of scope
            let proxy_request_sender = self.proxy_request_sender.clone();
            info.bind_to_scope(Box::new(move |request_info| {
                proxy_request_sender.unbounded_send(ProxyRequest::EndListen(request_info)).ok();
            }))
            .await;
            // Add the request to tracked listen requests.
            self.listen_requests.push(info.clone());
            // Listening requests must be acknowledged as they are long-living.
            info.acknowledge().await;
            // If listening state has changed, update state.
            if was_listening != self.is_listening() {
                self.send_listen_update(false).await;
            }
            // Request the active request be removed as it is now tracked
            // elsewhere.
            self.request(ProxyRequest::RemoveActive);
            return;
        }
        // If we have exceeded the maximum number of attempts, remove this
        // request from the queue.
        if active_request.attempts > self.max_attempts {
            publish!(
                self,
                event::handler::Event::Request(
                    event::handler::Action::AttemptsExceeded,
                    request.clone()
                )
            );
            self.request(ProxyRequest::RemoveActive);
            return;
        }
        publish!(
            self,
            event::handler::Event::Request(event::handler::Action::Execute, request.clone())
        );
        let mut receptor = self
            .messenger
            .message(
                setting_handler::Payload::Command(Command::HandleRequest(request.clone())).into(),
                Audience::Messenger(signature),
            )
            .set_timeout(self.request_timeout)
            .send();
        let proxy_request_sender_clone = self.proxy_request_sender.clone();
        fasync::Task::spawn(async move {
            while let Some(message_event) = receptor.next().await {
                let handler_result = match message_event {
                    MessageEvent::Message(
                        service::Payload::Controller(setting_handler::Payload::Result(result)),
                        _,
                    ) => Some(result),
                    MessageEvent::Status(Status::Undeliverable) => {
                        Some(Err(ControllerError::IrrecoverableError))
                    }
                    MessageEvent::Status(Status::Timeout) => {
                        Some(Err(ControllerError::TimeoutError))
                    }
                    _ => None,
                };
                if let Some(result) = handler_result {
                    // Mark the request as having been handled after retries have been
                    // attempted and the client has been notified.
                    proxy_request_sender_clone
                        .unbounded_send(ProxyRequest::HandleResult(result))
                        .ok();
                    return;
                }
            }
        })
        .detach();
    }
async fn execute_next_request ( & mut self , recreate_handler : bool ) { if self . active_request . is_none ( ) { // Add the request to the queue of requests to process. self . active_request = Some ( ActiveRequest { request : self . pending_requests . pop_front ( ) . expect ( " " ) , attempts : 0 , last_result : None , } ) ; } // Recreating signature is always honored, even if the request is not. let signature = self . get_handler_signature ( recreate_handler ) . await . expect ( " " ) ; // since we borrow self as mutable for active_request, we must retrieve // the listening state (which borrows immutable) before. let was_listening = self . is_listening ( ) ; let active_request = self . active_request . as_mut ( ) . expect ( " " ) ; active_request . attempts += 1 ; // Note that we must copy these values as we are borrowing self for // active_requests and self is needed to remove active below. let request = active_request . get_request ( ) ; if matches ! ( request Request Listen ) { let info = active_request . get_info ( ) ; // Add a callback when the client side goes out of scope let proxy_request_sender = self . proxy_request_sender . clone ( ) ; info . bind_to_scope ( Box :: new ( move | request_info | { proxy_request_sender . unbounded_send ( ProxyRequest :: EndListen ( request_info ) ) . ok ( ) ; } ) ) . await ; // Add the request to tracked listen requests. self . listen_requests . push ( info . clone ( ) ) ; // Listening requests must be acknowledged as they are long-living. info . acknowledge ( ) . await ; // If listening state has changed, update state. if was_listening != self . is_listening ( ) { self . send_listen_update ( false ) . await ; } // Request the active request be removed as it is now tracked // elsewhere. self . request ( ProxyRequest :: RemoveActive ) ; return ; } // If we have exceeded the maximum number of attempts, remove this // request from the queue. if active_request . attempts > self . max_attempts { publish ! ( self event handler Event Request ( event handler Action AttemptsExceeded request clone ( ) ) ) ; self . request ( ProxyRequest :: RemoveActive ) ; return ; } publish ! ( self event handler Event Request ( event handler Action Execute request clone ( ) ) ) ; let mut receptor = self . messenger . message ( setting_handler :: Payload :: Command ( Command :: HandleRequest ( request . clone ( ) ) ) . into ( ) , Audience :: Messenger ( signature ) , ) . set_timeout ( self . request_timeout ) . send ( ) ; let proxy_request_sender_clone = self . proxy_request_sender . clone ( ) ; fasync :: Task :: spawn ( async move { while let Some ( message_event ) = receptor . next ( ) . await { let handler_result = match message_event { MessageEvent :: Message ( service :: Payload :: Controller ( setting_handler :: Payload :: Result ( result ) ) , _ , ) => Some ( result ) , MessageEvent :: Status ( Status :: Undeliverable ) => { Some ( Err ( ControllerError :: IrrecoverableError ) ) } MessageEvent :: Status ( Status :: Timeout ) => { Some ( Err ( ControllerError :: TimeoutError ) ) } _ => None , } ; if let Some ( result ) = handler_result { // Mark the request as having been handled after retries have been // attempted and the client has been notified. proxy_request_sender_clone . unbounded_send ( ProxyRequest :: HandleResult ( result ) ) . ok ( ) ; return ; } } } ) . detach ( ) ; }
Processes the next request in the queue of pending requests.
Processes the next request in the queue of pending requests .
&mut self
recreate_handler
bool