pub async fn with_retry<T, E, F, Fut>(
config: &RetryConfig,
operation: F,
) -> Result<T, RetryError<E>>Expand description
Execute an async operation with retries
Uses exponential backoff with optional jitter. If the error provides a retry-after duration, that will be used instead of the calculated delay.
§Arguments
config- Retry configurationoperation- Async closure that returns Result<T, E>
§Returns
Ok(T)- If the operation succeedsErr(RetryError<E>)- If all retries are exhausted or error is not retryable
§Example
use yldfi_common::{with_retry, RetryConfig, RetryableError};
#[derive(Debug)]
struct ApiError { retryable: bool }
impl RetryableError for ApiError {
fn is_retryable(&self) -> bool { self.retryable }
}
async fn call_api() -> Result<String, ApiError> {
Ok("success".to_string())
}
async fn example() {
let config = RetryConfig::default();
let result = with_retry(&config, call_api).await;
}