/// Forwards request to proper sink. A new task is spawned in order to receive
/// the response. If no sink is available, an error is immediately reported
/// back.
Forwards request to proper sink. A new task is spawned in order to receive
the response. If no sink is available, an error is immediately reported
back.
Forwards request to proper sink . A new task is spawned in order to receive the response . If no sink is available an error is immediately reported back .
async fn process_request(
        &mut self,
        id: u64,
        setting_type: SettingType,
        request: SettingRequest,
        client: MessageClient,
    ) {
        let candidate = self.get_handler(setting_type).await;
        match candidate {
            None => {
                client
                    .reply(Payload::Event(SettingEvent::Response(
                        id,
                        Err(SwitchboardError::UnhandledType { setting_type: setting_type }),
                    )))
                    .send();
            }
            Some(command_sender) => {
                let (responder, receiver) =
                    futures::channel::oneshot::channel::<SettingResponseResult>();
                fasync::spawn(async move {
                    let response_result =
                        receiver.await.context("getting response from controller");
                    if response_result.is_err() {
                        client
                            .reply(Payload::Event(SettingEvent::Response(
                                id,
                                Err(SwitchboardError::UnexpectedError {
                                    description: "channel closed prematurely".to_string(),
                                }),
                            )))
                            .send();
                        return;
                    }
                    client
                        .reply(Payload::Event(SettingEvent::Response(id, response_result.unwrap())))
                        .send();
                });
                command_sender.unbounded_send(Command::HandleRequest(request, responder)).ok();
            }
        }
    }
async fn process_request ( & mut self , id : u64 , setting_type : SettingType , request : SettingRequest , client : MessageClient , ) { let candidate = self . get_handler ( setting_type ) . await ; match candidate { None => { client . reply ( Payload :: Event ( SettingEvent :: Response ( id , Err ( SwitchboardError :: UnhandledType { setting_type : setting_type } ) , ) ) ) . send ( ) ; } Some ( command_sender ) => { let ( responder , receiver ) = futures :: channel :: oneshot :: channel :: < SettingResponseResult > ( ) ; fasync :: spawn ( async move { let response_result = receiver . await . context ( " " ) ; if response_result . is_err ( ) { client . reply ( Payload :: Event ( SettingEvent :: Response ( id , Err ( SwitchboardError :: UnexpectedError { description : " " . to_string ( ) , } ) , ) ) ) . send ( ) ; return ; } client . reply ( Payload :: Event ( SettingEvent :: Response ( id , response_result . unwrap ( ) ) ) ) . send ( ) ; } ) ; command_sender . unbounded_send ( Command :: HandleRequest ( request , responder ) ) . ok ( ) ; } } }
Forwards request to proper sink.
Forwards request to proper sink .
&mut self
id
u64
setting_type
SettingType
request
SettingRequest
client
MessageClient