37 std::chrono::milliseconds
delay{0};
57 return {
false, std::chrono::milliseconds(0)};
73 double factor = 2.0,
bool jitter =
true) {
79 auto seed =
static_cast<unsigned int>(std::chrono::high_resolution_clock::now().time_since_epoch().count());
84 std::shared_ptr<ProtectedRng> shared_rng;
86 shared_rng = std::make_shared<ProtectedRng>();
91 if (!error_info.retryable) {
92 return {
false, std::chrono::milliseconds(0)};
95 double calculated =
static_cast<double>(min_delay.count()) * std::pow(factor, attempt_count);
96 double cap =
static_cast<double>(max_delay.count());
99 double delay_ms = std::min(calculated, cap);
102 std::lock_guard<std::mutex> lock(shared_rng->mtx);
104 std::uniform_real_distribution<> dist(0.0, delay_ms);
105 delay_ms = dist(shared_rng->rng);
108 return {
true, std::chrono::milliseconds(
static_cast<long long>(delay_ms))};
ReconnectPolicy FixedInterval(std::chrono::milliseconds delay)
Creates a policy that retries with a fixed interval.
std::function< ReconnectDecision(const diagnostics::ErrorInfo &, uint32_t)> ReconnectPolicy
Function type for determining reconnection policy.
ReconnectPolicy ExponentialBackoff(std::chrono::milliseconds min_delay, std::chrono::milliseconds max_delay, double factor=2.0, bool jitter=true)
Creates a policy that retries with exponential backoff.
Represents a decision on whether to retry a connection attempt.
std::chrono::milliseconds delay
Comprehensive error information structure.