Skip to content

Commit

Permalink
Sleep with the value of the current backoff
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Nov 12, 2024
1 parent d5eab16 commit 533fa5c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/core/src/control_flow/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,17 @@ impl<S: SleepStrategy> Sleep<S> {
/// Update the sleep strategy state, and sleep for the given backoff.
async fn sleep_update(&self, state: &mut S::State) {
self.strategy.next_state(state);
sleep(self.strategy.backoff(state)).await;
self.sleep_with_current_backoff(state).await;
}

/// Sleep for a [`Duration`] equivalent to the value of
/// the current backoff.
pub fn sleep_with_current_backoff(
&self,
state: &S::State,
) -> impl Future<Output = ()> + 'static {
let backoff_duration = self.strategy.backoff(state);
sleep(backoff_duration)
}

/// Run a future as many times as `iter_times`
Expand Down

0 comments on commit 533fa5c

Please sign in to comment.