stallBackoffDelay function
The stall backoff ladder (AC4): min(base * 2^(n-1), max) with base
5 s and cap 60 s — delays 5 s, 10 s, 20 s, 40 s, 60 s, 60 s, … Every
delay is within 5, 60 seconds (asserted by UT).
Implementation
Duration stallBackoffDelay(
int stallNumber, {
Duration base = const Duration(seconds: 5),
Duration max = const Duration(seconds: 60),
}) {
if (stallNumber <= 1) return base;
var delay = base;
for (var i = 1; i < stallNumber; i++) {
delay = delay * 2;
if (delay >= max) return max;
}
return delay < max ? delay : max;
}