/// Updates the App data, basically updates information on all the live matches
/// Also returns the indexes of the matches that are no longer live
Updates the App data, basically updates information on all the live matches
Also returns the indexes of the matches that are no longer live
Updates the App data basically updates information on all the live matches Also returns the indexes of the matches that are no longer live
pub async fn update_on_tick(&mut self) -> Vec<usize> {
        // WARN: Update algorithm might be slow for larger number of matches
        // For now this should be fine and not cause any bottlenecks
        let mut match_name_id: Vec<(String, String)> = vec![];
        let mut scorecard: Vec<MatchInningsInfo> = vec![];
        match get_all_live_matches_id_and_short_name(&self.req_clt).await {
            Ok(v) => match_name_id = v,
            Err(e) => {
                println!("{:?}", e);
            }
        };
        let mut non_live_matches_idx: Vec<usize> = vec![];
        for (idx, mi) in &mut self.matches_info.iter_mut().enumerate() {
            if match_name_id
                .iter()
                .any(|e| e.1 == mi.cricbuzz_match_id.to_string())
            {
                let mid = mi.cricbuzz_match_id;
                if let Ok(json) = get_match_info_from_id(&self.req_clt, mid).await {
                    if prepare_scorecard(&self.req_clt, mid, &mut scorecard)
                        .await
                        .is_ok()
                    {
                        mi.cricbuzz_info = json;
                        mi.scorecard = scorecard.clone();
                        scorecard.clear();
                    }
                }
            } else {
                non_live_matches_idx.push(idx);
            }
        }
        for i in &non_live_matches_idx {
            self.matches_info.remove(*i);
        }
        non_live_matches_idx
    }
pub async fn update_on_tick ( & mut self ) -> Vec < usize > { // WARN: Update algorithm might be slow for larger number of matches // For now this should be fine and not cause any bottlenecks let mut match_name_id : Vec < ( String , String ) > = vec ! [ ] ; let mut scorecard : Vec < MatchInningsInfo > = vec ! [ ] ; match get_all_live_matches_id_and_short_name ( & self . req_clt ) . await { Ok ( v ) => match_name_id = v , Err ( e ) => { println ! ( " " e ) ; } } ; let mut non_live_matches_idx : Vec < usize > = vec ! [ ] ; for ( idx , mi ) in & mut self . matches_info . iter_mut ( ) . enumerate ( ) { if match_name_id . iter ( ) . any ( | e | e . 1 == mi . cricbuzz_match_id . to_string ( ) ) { let mid = mi . cricbuzz_match_id ; if let Ok ( json ) = get_match_info_from_id ( & self . req_clt , mid ) . await { if prepare_scorecard ( & self . req_clt , mid , & mut scorecard ) . await . is_ok ( ) { mi . cricbuzz_info = json ; mi . scorecard = scorecard . clone ( ) ; scorecard . clear ( ) ; } } } else { non_live_matches_idx . push ( idx ) ; } } for i in & non_live_matches_idx { self . matches_info . remove ( * i ) ; } non_live_matches_idx }
Updates the App data, basically updates information on all the live matches
Also returns the indexes of the matches that are no longer live
Updates the App data basically updates information on all the live matches Also returns the indexes of the matches that are no longer live
&mut self