rust-tokio-retry
rust-tokio-retry copied to clipboard
exponential backoff is too exponential
I found this counterintuitive:
#[test]
fn backoff() {
let x: Vec<std::time::Duration> = tokio_retry::strategy::ExponentialBackoff::from_millis(50).take(5).collect();
dbg!(x);
}
x = [
50ms,
2.5s,
125s,
6250s,
312500s,
]
Looking at the source code I would have expected the calculation to be base * factor^retry
but it seems that it's base^retry * factor
. So to use this like I want it seems that I need to supply from_millis(2).factor(25)
.
Just swapping this would probably be a confusing breakage, perhaps from_millis could be replaced with from_base
? Then it would probably have made me realize that I was doing something wrong.