Skip to content
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

Ensure crumb is loaded before querying API #160

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ and `Removed`.

## [Unreleased]

### Fixed

- Race condition preventing data from loading if a long update interval was defined

## [0.14.9] - 2023-07-25

### Fixed
Expand Down
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ lazy_static! {
pub static ref SHOW_VOLUMES: RwLock<bool> = RwLock::new(OPTS.show_volumes);
pub static ref DEFAULT_TIMESTAMPS: RwLock<HashMap<TimeFrame, Vec<i64>>> = Default::default();
pub static ref THEME: theme::Theme = OPTS.theme.unwrap_or_default();
pub static ref YAHOO_CRUMB: RwLock<Option<CrumbData>> = RwLock::default();
pub static ref YAHOO_CRUMB: async_std::sync::RwLock<Option<CrumbData>> = Default::default();
}

fn main() {
Expand All @@ -56,6 +56,7 @@ fn main() {

setup_panic_hook();
setup_terminal();
set_crumb();

let request_redraw = REDRAW_REQUEST.0.clone();
let data_received = DATA_RECEIVED.1.clone();
Expand All @@ -80,8 +81,6 @@ fn main() {

let default_timestamp_service = DefaultTimestampService::new();

set_crumb();

let app = Arc::new(Mutex::new(app::App {
mode: starting_mode,
stocks: starting_stocks,
Expand Down Expand Up @@ -236,8 +235,10 @@ fn setup_panic_hook() {

fn set_crumb() {
async_std::task::spawn(async move {
let mut _guard = YAHOO_CRUMB.write().await;

if let Ok(crumb) = CLIENT.get_crumb().await {
*YAHOO_CRUMB.write() = Some(crumb);
*_guard = Some(crumb);
}
});
}
2 changes: 1 addition & 1 deletion src/task/company.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl AsyncTask for Company {
Box::pin(async move {
let symbol = input.as_ref();

let crumb = YAHOO_CRUMB.read().clone();
let crumb = YAHOO_CRUMB.read().await.clone();

if let Some(crumb) = crumb {
crate::CLIENT.get_company_data(symbol, crumb).await.ok()
Expand Down
2 changes: 1 addition & 1 deletion src/task/current_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl AsyncTask for CurrentPrice {
Box::pin(async move {
let symbol = input.as_ref();

let crumb = YAHOO_CRUMB.read().clone();
let crumb = YAHOO_CRUMB.read().await.clone();

if let Some(crumb) = crumb {
if let Ok(response) = crate::CLIENT.get_company_data(symbol, crumb).await {
Expand Down
Loading