Skip to main content

RetryExt

Trait RetryExt 

Source
pub trait RetryExt<T> {
    // Required method
    fn with_retry(
        self,
        config: &RetryConfig,
    ) -> impl Future<Output = AptosResult<T>>;
}
Expand description

Extension trait for adding retry capability to async operations.

A single Future cannot be retried because it is consumed the first time it is polled to completion. Retrying therefore requires a factory closure that can produce a fresh future on every attempt, so this trait is implemented for Fn() -> Future operation factories rather than for bare futures.

§Example

use aptos_sdk::retry::{RetryConfig, RetryExt};

let config = RetryConfig::default();
let result = (|| async { fetch_something().await }).with_retry(&config).await;

Required Methods§

Source

fn with_retry( self, config: &RetryConfig, ) -> impl Future<Output = AptosResult<T>>

Executes this operation factory under the given retry config.

The closure is invoked once per attempt, producing a fresh future each time, and retried according to config while the returned error is retryable.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<F, Fut, T> RetryExt<T> for F
where F: Fn() -> Fut, Fut: Future<Output = AptosResult<T>>,