pub struct RetryPolicy { /* private fields */ }Expand description
How reconnection attempts are spaced and how many are allowed.
When a stream connection breaks, this crate reconnects on its own — that is
the whole point of a protocol client. What it will not do is hide the
consequences: every attempt and every outcome is reported on the session
event stream, and when this policy’s budget runs out the session is
reported definitively lost rather than retried forever in silence
(docs/adr/0005-recovery-is-visible-in-the-event-stream.md).
Delays follow full jitter: the base delay doubles after each failure up
to RetryPolicy::max_delay, and the delay actually waited is drawn
uniformly from zero to that base. Jitter is this crate’s choice, not a
protocol rule; it exists so that a fleet of clients knocked off a server at
the same instant does not return in lockstep.
A successful bind resets the schedule, so a session that reconnects cleanly never carries delay over from an unrelated earlier failure.
§Examples
use std::time::Duration;
use lightstreamer_rs::RetryPolicy;
// Give up after three failures instead of the default eight.
let policy = RetryPolicy::default().with_max_attempts(std::num::NonZeroU32::new(3));
assert_eq!(policy.max_attempts().map(|n| n.get()), Some(3));Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub const fn with_initial_delay(self, delay: Duration) -> Self
pub const fn with_initial_delay(self, delay: Duration) -> Self
Sets the delay before the first reconnection attempt.
Sourcepub const fn with_max_delay(self, delay: Duration) -> Self
pub const fn with_max_delay(self, delay: Duration) -> Self
Sets the ceiling the delay grows to and does not exceed.
Sourcepub const fn with_max_attempts(self, attempts: Option<NonZeroU32>) -> Self
pub const fn with_max_attempts(self, attempts: Option<NonZeroU32>) -> Self
Sets how many consecutive failures are allowed before the session is reported definitively lost.
None retries forever. That is permitted, but then nothing ever tells
the caller “this is not coming back” except the individual attempt
events, so choose it deliberately.
Sourcepub const fn initial_delay(&self) -> Duration
pub const fn initial_delay(&self) -> Duration
The delay before the first reconnection attempt.
Sourcepub const fn max_attempts(&self) -> Option<NonZeroU32>
pub const fn max_attempts(&self) -> Option<NonZeroU32>
How many consecutive failures are allowed, or None for no limit.
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§fn clone(&self) -> RetryPolicy
fn clone(&self) -> RetryPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more