randomizedExponentialBackoff static method
Start with 1s delay and adds random timeout from 300ms to 3s
Implementation
static Future<void> randomizedExponentialBackoff(int retries) async {
int retryDelay = 1000; // start with 1s delay
for (int i = 0; i < retries; i++) {
retryDelay *= 2;
}
await Future<void>.delayed(
Duration(
milliseconds: retryDelay +
// add random timeout from 300ms to 3s
(_random.nextDouble() * (3000 - 300) + 300).floor(),
),
);
}