From 4167c17fc4814f0c482ff7cac2b11d3f5bf5ac23 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sun, 6 Oct 2024 17:48:50 +0200 Subject: [PATCH] Congest the code --- src/tui/app/machine/fetch_state.rs | 35 +++++++++++++----------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/tui/app/machine/fetch_state.rs b/src/tui/app/machine/fetch_state.rs index 14cd586..b08a96f 100644 --- a/src/tui/app/machine/fetch_state.rs +++ b/src/tui/app/machine/fetch_state.rs @@ -140,32 +140,27 @@ impl AppMachine { } pub fn app_fetch_next(inner: AppInner, mut fetch: FetchState) -> App { - match fetch.try_recv() { - Ok(fetch_result) => match fetch_result { - Ok(retval) => Self::handle_mb_api_return(inner, fetch, retval), - Err(fetch_err) => { - AppMachine::error_state(inner, format!("fetch failed: {fetch_err}")).into() - } - }, - Err(recv_err) => match recv_err { - TryRecvError::Empty => AppMachine::fetch_state(inner, fetch).into(), - TryRecvError::Disconnected => { + loop { + let app: App = match fetch.try_recv() { + Ok(fetch_result) => match fetch_result { + Ok(MbReturn::Match(next_match)) => { + AppMachine::match_state(inner, MatchState::new(next_match, fetch)).into() + } + Ok(MbReturn::Fetch(_)) => continue, + Err(fetch_err) => { + AppMachine::error_state(inner, format!("fetch failed: {fetch_err}")).into() + } + }, + Err(TryRecvError::Empty) => AppMachine::fetch_state(inner, fetch).into(), + Err(TryRecvError::Disconnected) => { if fetch.fetch_rx.is_some() { AppMachine::browse_state(inner).into() } else { Self::app_fetch_new(inner) } } - }, - } - } - - fn handle_mb_api_return(inner: AppInner, fetch: FetchState, retval: MbReturn) -> App { - match retval { - MbReturn::Match(next_match) => { - AppMachine::match_state(inner, MatchState::new(next_match, fetch)).into() - } - MbReturn::Fetch(_) => Self::app_fetch_next(inner, fetch), + }; + return app; } }