Skip to content

Commit

Permalink
feat: add UI for egui while waiting
Browse files Browse the repository at this point in the history
  • Loading branch information
c-git committed Jan 15, 2025
1 parent 142f0b3 commit e95f043
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/data_state_retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ impl<T, E: ErrorBounds> DataStateRetry<T, E> {
self.inner = DataState::default();
}
} else {
let wait_left = wait_before_next_attempt(self.next_allowed_attempt);
ui.colored_label(
ui.visuals().error_fg_color,
format!(
"{} attempt(s) left. {} seconds before retry. {e}",
self.attempts_left,
wait_left.as_secs()
),
);
let is_able_to_make_progress = self.get(fetch_fn).is_able_to_make_progress();
assert!(
is_able_to_make_progress,
Expand Down Expand Up @@ -163,10 +172,8 @@ impl<T, E: ErrorBounds> DataStateRetry<T, E> {
if self.attempts_left == 0 {
self.inner.get(fetch_fn)
} else {
let wait_duration_left = self
.next_allowed_attempt
.saturating_duration_since(Instant::now());
if wait_duration_left.is_zero() {
let wait_left = wait_before_next_attempt(self.next_allowed_attempt);
if wait_left.is_zero() {
warn!(?err_msg, ?self.attempts_left, "retrying request");
self.attempts_left -= 1;
self.inner = DataState::None;
Expand Down Expand Up @@ -233,3 +240,8 @@ impl<T, E: ErrorBounds> AsMut<DataStateRetry<T, E>> for DataStateRetry<T, E> {
self
}
}

/// The duration before the next attempt will be made
fn wait_before_next_attempt(next_allowed_attempt: Instant) -> Duration {
next_allowed_attempt.saturating_duration_since(Instant::now())
}

0 comments on commit e95f043

Please sign in to comment.