rust-tokio-retry icon indicating copy to clipboard operation
rust-tokio-retry copied to clipboard

Immediate retry?

Open inv2004 opened this issue 6 years ago • 1 comments

Hello, Just checked sources - looks like Delay is the only option used for retry.

Are there any way to produce "Immediate" retry?

Thank you,

inv2004 avatar Jul 27 '18 02:07 inv2004

The interface to Retry and RetryIf looks like:

pub fn spawn<T: IntoIterator<IntoIter = I, Item = Duration>>(
    strategy: T,
    action: A,
    condition: C
) -> RetryIf<I, A, C>

So you should be able to implement an Iterator that returns Durations in your desired pattern. If you want the first to be an immediate retry, and then a Exponential pattern, it would look like:

std::iter::once(Duration::from_secs(0))
    .chain(
        ExponentialBackoff::from_millis(100)
            .factor(3)
            .max_delay(Duration::from_secs(3))
    )

hgzimmerman avatar May 02 '21 14:05 hgzimmerman