RetryExt

Trait RetryExt 

Source
pub trait RetryExt: Future {
    // Required method
    fn timeout<'async_trait>(
        self,
        timeout: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Output, TimeoutError>> + Send + 'async_trait>>
       where Self: 'async_trait;
}
Expand description

An extension trait for Future that provides a convenient methods for retries.

Required Methods§

Source

fn timeout<'async_trait>( self, timeout: Duration, ) -> Pin<Box<dyn Future<Output = Result<Self::Output, TimeoutError>> + Send + 'async_trait>>
where Self: 'async_trait,

Transforms the current Future to a new one that is time-limited by the given timeout. Returns TimeoutError if timeout exceeds. Otherwise, it returns the original Future’s result. Example:

use fluvio_future::timer::sleep;
use fluvio_future::retry::RetryExt;
use fluvio_future::retry::TimeoutError;
use std::time::{Duration, Instant};

fluvio_future::task::run(async {
    let result = sleep(Duration::from_secs(10)).timeout(Duration::from_secs(1)).await;
    assert_eq!(result, Err(TimeoutError));
});

Implementors§

Source§

impl<F: Future + Send> RetryExt for F