pub async fn dispatch(
        &self,
        event: ComponentEvent,
    ) -> Result<Option<oneshot::Receiver<()>>, Error> {
        // TODO(fxb/48360): once flattening of monikers is done, we would expect to have a single
        // moniker here. For now taking the first one and ignoring the rest.
        // Ensure that the event is coming from a realm within the scope of this dispatcher.
        let maybe_scope_moniker = self
            .scope_monikers
            .iter()
            .filter(|moniker| moniker.contains_in_realm(&event.target_moniker))
            .next();
        if maybe_scope_moniker.is_none() {
            return Ok(None);
        }

        let scope_moniker = maybe_scope_moniker.unwrap().clone();

        trace::duration!("component_manager", "events:send");
        let event_type = format!("{:?}", event.payload.type_());
        let target_moniker = event.target_moniker.to_string();
        trace::flow_begin!(
            "component_manager",
            "event",
            event.id,
            "event_type" => event_type.as_str(),
            "target_moniker" => target_moniker.as_str()
        );
        let (maybe_responder_tx, maybe_responder_rx) = if self.sync_mode == SyncMode::Async {
            (None, None)
        } else {
            let (responder_tx, responder_rx) = oneshot::channel();
            (Some(responder_tx), Some(responder_rx))
        };
        {
            let mut tx = self.tx.lock().await;
            tx.send(Event { event, scope_moniker, responder: maybe_responder_tx }).await?;
        }
        Ok(maybe_responder_rx)
    }
/// Sends the event to an event stream, if fired in the scope of `scope_moniker`. Returns
/// a responder which can be blocked on.
Sends the event to an event stream, if fired in the scope of `scope_moniker`. Returns
a responder which can be blocked on.
Sends the event to an event stream if fired in the scope of ` scope_moniker ` . Returns a responder which can be blocked on .
pub async fn dispatch(
        &self,
        event: ComponentEvent,
    ) -> Result<Option<oneshot::Receiver<()>>, Error> {
        // TODO(fxb/48360): once flattening of monikers is done, we would expect to have a single
        // moniker here. For now taking the first one and ignoring the rest.
        // Ensure that the event is coming from a realm within the scope of this dispatcher.
        let maybe_scope_moniker = self
            .scope_monikers
            .iter()
            .filter(|moniker| moniker.contains_in_realm(&event.target_moniker))
            .next();
        if maybe_scope_moniker.is_none() {
            return Ok(None);
        }
        let scope_moniker = maybe_scope_moniker.unwrap().clone();
        trace::duration!("component_manager", "events:send");
        let event_type = format!("{:?}", event.payload.type_());
        let target_moniker = event.target_moniker.to_string();
        trace::flow_begin!(
            "component_manager",
            "event",
            event.id,
            "event_type" => event_type.as_str(),
            "target_moniker" => target_moniker.as_str()
        );
        let (maybe_responder_tx, maybe_responder_rx) = if self.sync_mode == SyncMode::Async {
            (None, None)
        } else {
            let (responder_tx, responder_rx) = oneshot::channel();
            (Some(responder_tx), Some(responder_rx))
        };
        {
            let mut tx = self.tx.lock().await;
            tx.send(Event { event, scope_moniker, responder: maybe_responder_tx }).await?;
        }
        Ok(maybe_responder_rx)
    }
pub async fn dispatch ( & self , event : ComponentEvent , ) -> Result < Option < oneshot :: Receiver < ( ) > > , Error > { // TODO(fxb/48360): once flattening of monikers is done, we would expect to have a single // moniker here. For now taking the first one and ignoring the rest. // Ensure that the event is coming from a realm within the scope of this dispatcher. let maybe_scope_moniker = self . scope_monikers . iter ( ) . filter ( | moniker | moniker . contains_in_realm ( & event . target_moniker ) ) . next ( ) ; if maybe_scope_moniker . is_none ( ) { return Ok ( None ) ; } let scope_moniker = maybe_scope_moniker . unwrap ( ) . clone ( ) ; trace :: duration ! ( " " " " ) ; let event_type = format ! ( " " event payload type_ ( ) ) ; let target_moniker = event . target_moniker . to_string ( ) ; trace :: flow_begin ! ( " " " " event id " " event_type as_str ( ) " " target_moniker as_str ( ) ) ; let ( maybe_responder_tx , maybe_responder_rx ) = if self . sync_mode == SyncMode :: Async { ( None , None ) } else { let ( responder_tx , responder_rx ) = oneshot :: channel ( ) ; ( Some ( responder_tx ) , Some ( responder_rx ) ) } ; { let mut tx = self . tx . lock ( ) . await ; tx . send ( Event { event , scope_moniker , responder : maybe_responder_tx } ) . await ? ; } Ok ( maybe_responder_rx ) }
Sends the event to an event stream, if fired in the scope of `scope_moniker`.
Sends the event to an event stream if fired in the scope of ` scope_moniker ` .
&self
event
ComponentEvent
&self
event
ComponentEvent