From 44b898ca06b65ba4ee5b594a07d4de3c6b9167a3 Mon Sep 17 00:00:00 2001 From: Myoungki Jung Date: Mon, 31 Jan 2022 16:57:35 +1000 Subject: [PATCH 1/2] fixed: app_rx thread not fetching news --- headlines/src/lib.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/headlines/src/lib.rs b/headlines/src/lib.rs index 9ea341b..95cb164 100644 --- a/headlines/src/lib.rs +++ b/headlines/src/lib.rs @@ -40,21 +40,18 @@ impl App for Headlines { let news_tx_web = news_tx.clone(); #[cfg(not(target_arch = "wasm32"))] - thread::spawn(move || { - if !api_key.is_empty() { - fetch_news(&api_key, &mut news_tx); - } else { - loop { - match app_rx.recv() { - Ok(Msg::ApiKeySet(api_key)) => { - fetch_news(&api_key, &mut news_tx); - } - Ok(Msg::Refresh) => { - fetch_news(&api_key, &mut news_tx); - } - Err(e) => { - tracing::error!("failed receiving msg: {}", e); - } + fetch_news(&api_key, &mut news_tx); + + #[cfg(not(target_arch = "wasm32"))] + thread::spawn(move || loop { + + if let Ok(rx) = app_rx.recv() { + match rx { + Msg::ApiKeySet(api_key) => { + fetch_news(&api_key, &mut news_tx); + } + Msg::Refresh => { + fetch_news(&api_key, &mut news_tx); } } } From df876f9da28215ec1c8f482578e6b1e39dc17de1 Mon Sep 17 00:00:00 2001 From: Myoungki Jung Date: Mon, 31 Jan 2022 17:50:56 +1000 Subject: [PATCH 2/2] fixed: apikey provided condition --- headlines/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/headlines/src/lib.rs b/headlines/src/lib.rs index 95cb164..449b24f 100644 --- a/headlines/src/lib.rs +++ b/headlines/src/lib.rs @@ -40,8 +40,10 @@ impl App for Headlines { let news_tx_web = news_tx.clone(); #[cfg(not(target_arch = "wasm32"))] - fetch_news(&api_key, &mut news_tx); - + if !api_key.is_empty() { + fetch_news(&api_key, &mut news_tx); + } + #[cfg(not(target_arch = "wasm32"))] thread::spawn(move || loop {