From 533fa5cc195bbbb5110f7a74c1482ffb0b9c4682 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Mon, 11 Nov 2024 13:43:26 +0000 Subject: [PATCH] Sleep with the value of the current backoff --- crates/core/src/control_flow/time.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/core/src/control_flow/time.rs b/crates/core/src/control_flow/time.rs index e5d974181f..46d85ad79d 100644 --- a/crates/core/src/control_flow/time.rs +++ b/crates/core/src/control_flow/time.rs @@ -256,7 +256,17 @@ impl Sleep { /// 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 + 'static { + let backoff_duration = self.strategy.backoff(state); + sleep(backoff_duration) } /// Run a future as many times as `iter_times`