From 47565bab8c414ee1bdf740d64d87f75ab9c00d94 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Thu, 16 Apr 2026 15:37:26 +0200 Subject: [PATCH] Make const durations in forwarder actual Duration values --- src/forwarder.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/forwarder.rs b/src/forwarder.rs index e0d4bcf..376d073 100644 --- a/src/forwarder.rs +++ b/src/forwarder.rs @@ -22,11 +22,11 @@ use crate::api; use crate::notifier::Notifier; use crate::stream::{Event, Subscriber}; -const PING_INTERVAL: u64 = 15; -const PING_TIMEOUT: u64 = 10; -const SEND_TIMEOUT: u64 = 10; -const RECONNECT_DELAY_BASE: u64 = 500; -const RECONNECT_DELAY_CAP: u64 = 10_000; +const PING_INTERVAL: Duration = Duration::from_secs(15); +const PING_TIMEOUT: Duration = Duration::from_secs(10); +const SEND_TIMEOUT: Duration = Duration::from_secs(10); +const RECONNECT_DELAY_BASE_MS: u64 = 500; +const RECONNECT_DELAY_CAP_MS: u64 = 10_000; pub async fn forward( url: url::Url, @@ -192,7 +192,7 @@ where ping = pings.next() => { send_with_timeout(&mut sink, ping.unwrap()).await??; - ping_timeout = Box::pin(time::sleep(Duration::from_secs(PING_TIMEOUT))); + ping_timeout = Box::pin(time::sleep(PING_TIMEOUT)); } _ = &mut ping_timeout => bail!("ping timeout"), @@ -223,7 +223,7 @@ async fn send_with_timeout( sink: &mut SplitSink>, Message>, message: Message, ) -> anyhow::Result> { - time::timeout(Duration::from_secs(SEND_TIMEOUT), sink.send(message)) + time::timeout(SEND_TIMEOUT, sink.send(message)) .await .map_err(|_| anyhow!("send timeout")) } @@ -249,7 +249,7 @@ fn handle_close_frame(frame: Option) -> anyhow::Result<()> { fn exponential_delay(attempt: usize) -> u64 { let mut rng = rand::rng(); let attempt = attempt.min(10); - let exp = (RECONNECT_DELAY_BASE * 2_u64.pow(attempt as u32)).min(RECONNECT_DELAY_CAP); + let exp = (RECONNECT_DELAY_BASE_MS * 2_u64.pow(attempt as u32)).min(RECONNECT_DELAY_CAP_MS); rng.random_range((exp / 2)..exp) } @@ -269,7 +269,7 @@ fn close_message() -> Message { } fn ping_stream() -> impl Stream { - IntervalStream::new(time::interval(Duration::from_secs(PING_INTERVAL))) + IntervalStream::new(time::interval(PING_INTERVAL)) .skip(1) .map(|_| Message::Ping(vec![].into())) }