From 84a57bd8c08374f48ac0d0f8837ba4958b0789d2 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Wed, 29 Mar 2023 00:43:39 -0700 Subject: fix(stocks): 0.10.10 <- 0.11.10 to fix tokio thread panic --- src/modules/stocks.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/modules') diff --git a/src/modules/stocks.rs b/src/modules/stocks.rs index 33beeb8..bc07f71 100644 --- a/src/modules/stocks.rs +++ b/src/modules/stocks.rs @@ -75,12 +75,15 @@ impl Quote { fn symbol_to_string(symbol: &str) -> String { let mut quote = None; - if let Ok(response) = reqwest::blocking::get(format!( - "https://finnhub.io/api/v1/quote?symbol={}&token={}", - symbol, - std::env::var("FINNHUB_TOKEN") - .expect("could not locate FINNHUB_TOKEN environment variable") - )) { + // https://github.com/seanmonstar/reqwest/issues/1017#issuecomment-1157260218 + if let Ok(response) = tokio::task::block_in_place(|| { + reqwest::blocking::get(&format!( + "https://finnhub.io/api/v1/quote?symbol={}&token={}", + symbol, + std::env::var("FINNHUB_TOKEN") + .expect("could not locate FINNHUB_TOKEN environment variable") + )) + }) { if let Ok(response_content) = response.json::() { if response_content.dp.is_some() { quote = Some(response_content); -- cgit v1.2.3