Congest the code

This commit is contained in:
Wojciech Kozlowski 2024-10-06 17:48:50 +02:00
parent f202bfdc0a
commit 4167c17fc4

View File

@ -140,32 +140,27 @@ impl AppMachine<FetchState> {
}
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;
}
}