use std::time::Duration;
use crate::{RetryDelay, RetryJitter, RetryOptions};
pub(crate) const DEFAULT_SSE_MAX_RECONNECT_DELAY: Duration = Duration::from_secs(30);
pub(crate) const DEFAULT_SSE_RECONNECT_BACKOFF_MULTIPLIER: f64 = 2.0;
pub(crate) const DEFAULT_SSE_MAX_RECONNECTS: u32 = 3;
fn default_sse_retry_options() -> RetryOptions {
RetryOptions::new(
DEFAULT_SSE_MAX_RECONNECTS + 1,
None,
None,
RetryDelay::exponential(
Duration::from_secs(1),
DEFAULT_SSE_MAX_RECONNECT_DELAY,
DEFAULT_SSE_RECONNECT_BACKOFF_MULTIPLIER,
),
RetryJitter::None,
)
.expect("SSE default retry options must be valid")
}
#[derive(Debug, Clone, PartialEq)]
pub struct SseReconnectOptions {
pub retry: RetryOptions,
pub reconnect_on_eof: bool,
pub honor_server_retry: bool,
pub server_retry_max_delay: Option<Duration>,
pub apply_jitter_to_server_retry: bool,
}
impl Default for SseReconnectOptions {
fn default() -> Self {
Self {
retry: default_sse_retry_options(),
reconnect_on_eof: true,
honor_server_retry: true,
server_retry_max_delay: None,
apply_jitter_to_server_retry: true,
}
}
}
impl SseReconnectOptions {
pub fn new() -> Self {
Self::default()
}
}