Skip to content

fixed: app_rx thread not fetching news #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions headlines/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,20 @@ 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);
}
if !api_key.is_empty() {
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);
}
}
}
Expand Down