From 10e1ad60030f45b64edc79adf0a939bee8dc7bea Mon Sep 17 00:00:00 2001 From: Joscha Date: Mon, 22 Aug 2022 18:26:50 +0200 Subject: [PATCH] Reconect immediately on login/logout --- src/euph/room.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/euph/room.rs b/src/euph/room.rs index 681e2b9..33b13fe 100644 --- a/src/euph/room.rs +++ b/src/euph/room.rs @@ -101,7 +101,8 @@ impl State { ) -> anyhow::Result<()> { loop { info!("e&{}: connecting", name); - if let Some((conn_tx, mut conn_rx)) = Self::connect(vault, name).await? { + let connected = if let Some((conn_tx, mut conn_rx)) = Self::connect(vault, name).await? + { info!("e&{}: connected", name); event_tx.send(Event::Connected(conn_tx))?; @@ -111,11 +112,19 @@ impl State { info!("e&{}: disconnected", name); event_tx.send(Event::Disconnected)?; + + true } else { info!("e&{}: could not connect", name); event_tx.send(Event::Disconnected)?; + false + }; + + // Only delay reconnecting if the previous attempt failed. This way, + // we'll reconnect immediately if we login or logout. + if !connected { + tokio::time::sleep(RECONNECT_INTERVAL).await; } - tokio::time::sleep(RECONNECT_INTERVAL).await; } }