|
40 | 40 | },
|
41 | 41 | time::Duration,
|
42 | 42 | },
|
43 |
| - tokio::sync::{broadcast::Receiver, watch}, |
| 43 | + tokio::{ |
| 44 | + sync::{broadcast::Receiver, watch}, |
| 45 | + time::Instant, |
| 46 | + }, |
44 | 47 | };
|
45 | 48 |
|
46 | 49 | const PING_INTERVAL_DURATION: Duration = Duration::from_secs(30);
|
@@ -253,7 +256,7 @@ pub struct Subscriber<S> {
|
253 | 256 | sender: SplitSink<WebSocket, Message>,
|
254 | 257 | price_feeds_with_config: HashMap<PriceIdentifier, PriceFeedClientConfig>,
|
255 | 258 | ping_interval: tokio::time::Interval,
|
256 |
| - connection_timeout: tokio::time::Sleep, |
| 259 | + connection_deadline: Instant, |
257 | 260 | exit: watch::Receiver<bool>,
|
258 | 261 | responded_to_ping: bool,
|
259 | 262 | }
|
@@ -282,7 +285,7 @@ where
|
282 | 285 | sender,
|
283 | 286 | price_feeds_with_config: HashMap::new(),
|
284 | 287 | ping_interval: tokio::time::interval(PING_INTERVAL_DURATION),
|
285 |
| - connection_timeout: tokio::time::sleep(MAX_CONNECTION_DURATION), |
| 288 | + connection_deadline: Instant::now() + MAX_CONNECTION_DURATION, |
286 | 289 | exit: crate::EXIT.subscribe(),
|
287 | 290 | responded_to_ping: true, // We start with true so we don't close the connection immediately
|
288 | 291 | }
|
@@ -328,7 +331,7 @@ where
|
328 | 331 | self.sender.send(Message::Ping(vec![])).await?;
|
329 | 332 | Ok(())
|
330 | 333 | },
|
331 |
| - _ = &mut self.connection_timeout => { |
| 334 | + _ = tokio::time::sleep_until(self.connection_deadline) => { |
332 | 335 | tracing::info!(
|
333 | 336 | id = self.id,
|
334 | 337 | ip = ?self.ip_addr,
|
|
0 commit comments