Reconect immediately on login/logout

This commit is contained in:
Joscha 2022-08-22 18:26:50 +02:00
parent 7ca6ed5496
commit 10e1ad6003

View file

@ -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;
}
}