Skip to main content

with_backoff

Function with_backoff 

Source
pub async fn with_backoff<F, Fut, T, E>(
    config: &RetryConfig,
    f: F,
) -> Result<T, RetryError<E>>
where F: FnMut() -> Fut, Fut: Future<Output = Result<T, E>>, E: IsRetryable + Display,
Expand description

Retry an async operation with exponential backoff.

Calls f repeatedly until it succeeds or the max retries are exhausted. On each retryable error, waits for the calculated backoff delay before retrying. Non-retryable errors are returned immediately.

§Example

ⓘ
use retry_backoff::{with_backoff, RetryConfig};

let result = with_backoff(&RetryConfig::default(), || async {
    client.get("https://api.example.com/data").await
}).await;