pub struct SseRetryConfig {
pub max_retries: u32,
pub max_backoff_ms: u32,
pub min_sleep_ms: u32,
pub backoff_multiplier: f32,
pub jitter: bool,
}Expand description
Configuration for exponential backoff and jitter during stream reconnections.
Fields§
§max_retries: u32The maximum number of consecutive connection attempts before giving up.
max_backoff_ms: u32The absolute maximum wait time between connection attempts in milliseconds.
min_sleep_ms: u32The absolute minimum wait time between connection attempts in milliseconds.
backoff_multiplier: f32The multiplier applied to the delay after each failed attempt.
jitter: boolWhether to apply randomness (jitter) to the reconnect delay.
Implementations§
Source§impl SseRetryConfig
impl SseRetryConfig
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new retry configuration with sensible defaults.
The default configuration applies an exponential backoff multiplier of 2.0, caps the
maximum delay at 60,000 milliseconds (1 minute), caps the number of retries to 20, and
enables jitter to prevent thundering herd scenarios.
§Example
use sse_core::SseRetryConfig;
let config = SseRetryConfig::new();
assert_eq!(config.max_backoff_ms, 60_000);
assert!(config.jitter);Sourcepub const fn disabled() -> Self
pub const fn disabled() -> Self
Creates a retry configuration that disables all automatic retries.
Sourcepub fn calculate_backoff_with_factor(
&self,
reconnect_time_ms: u32,
attempt: u32,
jitter_factor: f32,
) -> Option<Duration>
pub fn calculate_backoff_with_factor( &self, reconnect_time_ms: u32, attempt: u32, jitter_factor: f32, ) -> Option<Duration>
Calculates the delay duration for the next reconnection attempt.
Returns None if the attempt count exceeds Self::max_retries.
Sourcepub fn calculate_backoff(
&self,
reconnect_time_ms: u32,
attempt: u32,
) -> Option<Duration>
pub fn calculate_backoff( &self, reconnect_time_ms: u32, attempt: u32, ) -> Option<Duration>
Calculates the delay duration for the next reconnection attempt.
Returns None if the attempt count exceeds Self::max_retries.
Trait Implementations§
Source§impl Clone for SseRetryConfig
impl Clone for SseRetryConfig
Source§fn clone(&self) -> SseRetryConfig
fn clone(&self) -> SseRetryConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more