pub trait RetryPolicy:
Debug
+ Send
+ Sync {
// Required methods
fn is_expired(
&self,
duration_since_start: Duration,
retry_count: u32,
) -> bool;
fn sleep_duration(&self, retry_count: u32) -> Duration;
// Provided method
fn wait<'life0, 'life1, 'async_trait>(
&'life0 self,
_error: &'life1 Error,
retry_count: u32,
retry_after: Option<Duration>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}
Expand description
A retry policy.
In the simple form, the policies need only differ in how they determine if the retry has expired and for how long they should sleep between retries.
wait
can be implemented in more complex cases where a simple test of time
is not enough.
Required Methods§
sourcefn is_expired(&self, duration_since_start: Duration, retry_count: u32) -> bool
fn is_expired(&self, duration_since_start: Duration, retry_count: u32) -> bool
Determine if no more retries should be performed.
Must return true if no more retries should be attempted.
sourcefn sleep_duration(&self, retry_count: u32) -> Duration
fn sleep_duration(&self, retry_count: u32) -> Duration
Determine how long before the next retry should be attempted.
Provided Methods§
sourcefn wait<'life0, 'life1, 'async_trait>(
&'life0 self,
_error: &'life1 Error,
retry_count: u32,
retry_after: Option<Duration>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn wait<'life0, 'life1, 'async_trait>(
&'life0 self,
_error: &'life1 Error,
retry_count: u32,
retry_after: Option<Duration>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
A Future that will wait until the request can be retried.
error
is the Error
value the led to a retry attempt.
retry_after
is the duration to wait before retrying, if provided by the server response.