22 : cfg_(cfg), rng_(seed) {
28 std::uint32_t
next_ms() noexcept {
30 if (attempt_ < 31) ++attempt_;
31 const double fixed =
static_cast<double>(cap) * (1.0 - cfg_.
jitter);
32 const double random_span =
static_cast<double>(cap) * cfg_.
jitter;
33 std::uniform_real_distribution<double> dist(0.0, 1.0);
34 const double delay = fixed + random_span * dist(rng_);
35 return static_cast<std::uint32_t
>(std::llround(delay));
38 void reset() noexcept { attempt_ = 0; }
39 std::uint32_t
attempt() const noexcept {
return attempt_; }
44 const std::uint64_t raw =
static_cast<std::uint64_t
>(cfg_.
base_ms)
46 return static_cast<std::uint32_t
>(std::min<std::uint64_t>(raw, cfg_.
max_ms));
52 std::uint32_t attempt_ = 0;
Definition backoff.hpp:21
std::uint32_t attempt() const noexcept
Definition backoff.hpp:41
std::uint32_t next_ms() noexcept
Delay for the current attempt in milliseconds; advances the attempt counter.
Definition backoff.hpp:30
std::uint32_t capped_delay(std::uint32_t attempt) const noexcept
Upper bound of the delay for attempt n (before jitter) - exposed for tests/metrics.
Definition backoff.hpp:45
const BackoffConfig & config() const noexcept
Definition backoff.hpp:42
void reset() noexcept
Definition backoff.hpp:40
Definition reactor.hpp:37
Definition backoff.hpp:15
double jitter
fraction of the capped delay that is randomised, in [0, 1]
Definition backoff.hpp:18
std::uint32_t base_ms
Definition backoff.hpp:16
std::uint32_t max_ms
Definition backoff.hpp:17