/// Returns a handle to a RegistryImpl which is listening to SettingAction from the
/// provided receiver and will send responses/updates on the given sender.
Returns a handle to a RegistryImpl which is listening to SettingAction from the
provided receiver and will send responses/updates on the given sender.
Returns a handle to a RegistryImpl which is listening to SettingAction from the provided receiver and will send responses / updates on the given sender .
pub async fn create(
        handler_factory: Arc<Mutex<dyn SettingHandlerFactory + Send + Sync>>,
        messenger_factory: MessengerFactory,
    ) -> Result<Arc<Mutex<RegistryImpl>>, Error> {
        let (notification_tx, mut notification_rx) =
            futures::channel::mpsc::unbounded::<SettingType>();
        let messenger_result =
            messenger_factory.create(MessengerType::Addressable(Address::Registry)).await;
        if let Err(error) = messenger_result {
            return Err(Error::new(error));
        }
        let (messenger_client, mut receptor) = messenger_result.unwrap();
        // We must create handle here rather than return back the value as we
        // reference the registry in the async tasks below.
        let registry = Arc::new(Mutex::new(Self {
            command_sender_map: HashMap::new(),
            notification_sender: notification_tx,
            active_listeners: vec![],
            handler_factory: handler_factory,
            messenger_client: messenger_client,
        }));
        // Async task for handling messages from the receptor.
        {
            let registry_clone = registry.clone();
            fasync::spawn(async move {
                while let Ok(event) = receptor.watch().await {
                    match event {
                        MessageEvent::Message(Payload::Action(action), client) => {
                            registry_clone.lock().await.process_action(action, client).await;
                        }
                        _ => {}
                    }
                }
            });
        }
        // An async task is spawned here to listen for notifications. The receiver
        // handles notifications from all sources.
        {
            let registry_clone = registry.clone();
            fasync::spawn(
                async move {
                    while let Some(setting_type) = notification_rx.next().await {
                        registry_clone.lock().await.notify(setting_type);
                    }
                    Ok(())
                }
                .unwrap_or_else(|_e: anyhow::Error| {}),
            );
        }
        Ok(registry)
    }
pub async fn create ( handler_factory : Arc < Mutex < dyn SettingHandlerFactory + Send + Sync > > , messenger_factory : MessengerFactory , ) -> Result < Arc < Mutex < RegistryImpl > > , Error > { let ( notification_tx , mut notification_rx ) = futures :: channel :: mpsc :: unbounded :: < SettingType > ( ) ; let messenger_result = messenger_factory . create ( MessengerType :: Addressable ( Address :: Registry ) ) . await ; if let Err ( error ) = messenger_result { return Err ( Error :: new ( error ) ) ; } let ( messenger_client , mut receptor ) = messenger_result . unwrap ( ) ; // We must create handle here rather than return back the value as we // reference the registry in the async tasks below. let registry = Arc :: new ( Mutex :: new ( Self { command_sender_map : HashMap :: new ( ) , notification_sender : notification_tx , active_listeners : vec ! [ ] , handler_factory : handler_factory , messenger_client : messenger_client , } ) ) ; // Async task for handling messages from the receptor. { let registry_clone = registry . clone ( ) ; fasync :: spawn ( async move { while let Ok ( event ) = receptor . watch ( ) . await { match event { MessageEvent :: Message ( Payload :: Action ( action ) , client ) => { registry_clone . lock ( ) . await . process_action ( action , client ) . await ; } _ => { } } } } ) ; } // An async task is spawned here to listen for notifications. The receiver // handles notifications from all sources. { let registry_clone = registry . clone ( ) ; fasync :: spawn ( async move { while let Some ( setting_type ) = notification_rx . next ( ) . await { registry_clone . lock ( ) . await . notify ( setting_type ) ; } Ok ( ( ) ) } . unwrap_or_else ( | _e : anyhow :: Error | { } ) , ) ; } Ok ( registry ) }
Returns a handle to a RegistryImpl which is listening to SettingAction from the
provided receiver and will send responses/updates on the given sender.
Returns a handle to a RegistryImpl which is listening to SettingAction from the provided receiver and will send responses / updates on the given sender .
handler_factory
Arc<Mutex<dyn SettingHandlerFactory + Send + Sync>>
messenger_factory
MessengerFactory