// It's the base routine: sends received updates to particular handlers: observer or auth_state handler
It's the base routine: sends received updates to particular handlers: observer or auth_state handler
It ' s the base routine : sends received updates to particular handlers : observer or auth_state handler
fn init_updates_task(&self, auth_sx: mpsc::Sender<UpdateAuthorizationState>) -> JoinHandle<()> {
        let run_flag = self.run_flag.clone();
        let clients = self.clients.clone();
        let recv_timeout = self.read_updates_timeout;
        let send_timeout = self.channels_send_timeout;
        let tdlib_client = Arc::new(self.tdlib_client.clone());
        tokio::spawn(async move {
            let current = tokio::runtime::Handle::try_current().unwrap();
            while run_flag.load(Ordering::Acquire) {
                let cl = tdlib_client.clone();
                if let Some(json) = current
                    .spawn_blocking(move || cl.receive(recv_timeout.as_secs_f64()))
                    .await
                    .unwrap()
                {
                    log::trace!("received json from tdlib: {}", json);
                    match from_json::<TdType>(&json) {
                        Err(e) => log::error!("can't deserialize tdlib data: {}", e),
                        Ok(t) => {
                            if let Some(TdType::Update(update)) = OBSERVER.notify(t) {
                                if let Update::AuthorizationState(auth_state) = update {
                                    log::trace!("auth state send: {:?}", auth_state);
                                    match auth_sx.send_timeout(auth_state, send_timeout).await {
                                        Ok(_) => {
                                            log::trace!("auth state sent");
                                        }
                                        Err(err) => {
                                            log::error!("can't send auth state update: {}", err)
                                        }
                                    };
                                } else if let Some(client_id) = update.client_id() {
                                    match clients.read().await.get(&client_id) {
                                        None => {
                                            log::warn!(
                                                "found updates for unavailable client ({})",
                                                client_id
                                            )
                                        }
                                        Some(ctx) => {
                                            if let Some(sender) = ctx.client().updates_sender() {
                                                log::trace!("sending update to client");
                                                match sender
                                                    .send_timeout(Box::new(update), send_timeout)
                                                    .await
                                                {
                                                    Ok(_) => {
                                                        log::trace!("update sent");
                                                    }
                                                    Err(err) => {
                                                        log::error!("can't send update: {}", err)
                                                    }
                                                };
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    };
                }
            }
        })
    }
fn init_updates_task ( & self , auth_sx : mpsc :: Sender < UpdateAuthorizationState > ) -> JoinHandle < ( ) > { let run_flag = self . run_flag . clone ( ) ; let clients = self . clients . clone ( ) ; let recv_timeout = self . read_updates_timeout ; let send_timeout = self . channels_send_timeout ; let tdlib_client = Arc :: new ( self . tdlib_client . clone ( ) ) ; tokio :: spawn ( async move { let current = tokio :: runtime :: Handle :: try_current ( ) . unwrap ( ) ; while run_flag . load ( Ordering :: Acquire ) { let cl = tdlib_client . clone ( ) ; if let Some ( json ) = current . spawn_blocking ( move | | cl . receive ( recv_timeout . as_secs_f64 ( ) ) ) . await . unwrap ( ) { log :: trace ! ( " " json ) ; match from_json :: < TdType > ( & json ) { Err ( e ) => log :: error ! ( " " e ) , Ok ( t ) => { if let Some ( TdType :: Update ( update ) ) = OBSERVER . notify ( t ) { if let Update :: AuthorizationState ( auth_state ) = update { log :: trace ! ( " " auth_state ) ; match auth_sx . send_timeout ( auth_state , send_timeout ) . await { Ok ( _ ) => { log :: trace ! ( " " ) ; } Err ( err ) => { log :: error ! ( " " err ) } } ; } else if let Some ( client_id ) = update . client_id ( ) { match clients . read ( ) . await . get ( & client_id ) { None => { log :: warn ! ( " " client_id ) } Some ( ctx ) => { if let Some ( sender ) = ctx . client ( ) . updates_sender ( ) { log :: trace ! ( " " ) ; match sender . send_timeout ( Box :: new ( update ) , send_timeout ) . await { Ok ( _ ) => { log :: trace ! ( " " ) ; } Err ( err ) => { log :: error ! ( " " err ) } } ; } } } } } } } ; } } } ) }
It's the base routine: sends received updates to particular handlers: observer or auth_state handler
It ' s the base routine : sends received updates to particular handlers : observer or auth_state handler
&self
auth_sx
mpsc::Sender<UpdateAuthorizationState>