pub fn lazy_load_story_comments(&self, story_id: u32) -> Result<CommentReceiver> {
        let request_url = format!("{}/item/{}.json", HN_OFFICIAL_PREFIX, story_id);
        let mut ids = log!(
            self.client
                .get(&request_url)
                .call()?
                .into_json::<HNStoryResponse>()?
                .kids,
            format!("get story (id={}) using {}", story_id, request_url)
        );

        let (sender, receiver) = crossbeam_channel::bounded(32);
        let client = self.clone();

        // loads first 5 comments to ensure the corresponding `CommentView` has data to render
        Self::load_comments(&client, &sender, &mut ids, 5)?;
        // used to test loading bar
        // std::thread::sleep(std::time::Duration::from_secs(1000));
        std::thread::spawn(move || {
            let sleep_dur = std::time::Duration::from_millis(1000);
            while !ids.is_empty() {
                if let Err(err) = Self::load_comments(&client, &sender, &mut ids, 5) {
                    warn!("encountered an error when loading comments: {}", err);
                    break;
                }
                std::thread::sleep(sleep_dur);
            }
        });
        Ok(receiver)
    }
/// Lazily load a story's comments
Lazily load a story's comments
Lazily load a story ' s comments
pub fn lazy_load_story_comments(&self, story_id: u32) -> Result<CommentReceiver> {
        let request_url = format!("{}/item/{}.json", HN_OFFICIAL_PREFIX, story_id);
        let mut ids = log!(
            self.client
                .get(&request_url)
                .call()?
                .into_json::<HNStoryResponse>()?
                .kids,
            format!("get story (id={}) using {}", story_id, request_url)
        );
        let (sender, receiver) = crossbeam_channel::bounded(32);
        let client = self.clone();
        // loads first 5 comments to ensure the corresponding `CommentView` has data to render
        Self::load_comments(&client, &sender, &mut ids, 5)?;
        // used to test loading bar
        // std::thread::sleep(std::time::Duration::from_secs(1000));
        std::thread::spawn(move || {
            let sleep_dur = std::time::Duration::from_millis(1000);
            while !ids.is_empty() {
                if let Err(err) = Self::load_comments(&client, &sender, &mut ids, 5) {
                    warn!("encountered an error when loading comments: {}", err);
                    break;
                }
                std::thread::sleep(sleep_dur);
            }
        });
        Ok(receiver)
    }
pub fn lazy_load_story_comments ( & self , story_id : u32 ) -> Result < CommentReceiver > { let request_url = format ! ( " " HN_OFFICIAL_PREFIX story_id ) ; let mut ids = log ! ( self client get ( request_url ) call ( ) into_json HNStoryResponse ( ) kids format ( " " story_id request_url ) ) ; let ( sender , receiver ) = crossbeam_channel :: bounded ( 32 ) ; let client = self . clone ( ) ; // loads first 5 comments to ensure the corresponding `CommentView` has data to render Self :: load_comments ( & client , & sender , & mut ids , 5 ) ? ; // used to test loading bar // std::thread::sleep(std::time::Duration::from_secs(1000)); std :: thread :: spawn ( move | | { let sleep_dur = std :: time :: Duration :: from_millis ( 1000 ) ; while ! ids . is_empty ( ) { if let Err ( err ) = Self :: load_comments ( & client , & sender , & mut ids , 5 ) { warn ! ( " " err ) ; break ; } std :: thread :: sleep ( sleep_dur ) ; } } ) ; Ok ( receiver ) }
Lazily load a story's comments
Lazily load a story ' s comments
&self
story_id
u32