From 70d4d6c56f05ae75b407242bf1b062b99230b58c Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Sat, 18 Mar 2023 18:41:58 +0100 Subject: [PATCH] feat(core): Use _testAndSetIsConnectionRunning --- packages/moxxmpp/lib/src/connection.dart | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/moxxmpp/lib/src/connection.dart b/packages/moxxmpp/lib/src/connection.dart index 4ff386b..b338394 100644 --- a/packages/moxxmpp/lib/src/connection.dart +++ b/packages/moxxmpp/lib/src/connection.dart @@ -1140,7 +1140,17 @@ class XmppConnection { bool waitUntilLogin = false, bool enableReconnectOnSuccess = true, }) async { - _runPreConnectionAssertions(); + if (await _testAndSetIsConnectionRunning()) { + _log.fine( + 'Cancelling this connection attempt as one appears to be already running.', + ); + return Future.value( + Result( + ConnectionAlreadyRunningError(), + ), + ); + } + await _resetIsConnectionRunning(); if (waitUntilLogin) { @@ -1230,17 +1240,7 @@ class XmppConnection { bool waitUntilLogin = false, bool enableReconnectOnSuccess = true, }) async { - if (_connectionState != XmppConnectionState.notConnected && - _connectionState != XmppConnectionState.error) { - _log.fine( - 'Cancelling this connection attempt as one appears to be already running.', - ); - return Future.value( - Result( - ConnectionAlreadyRunningError(), - ), - ); - } + _runPreConnectionAssertions(); final result = _connectImpl( lastResource: lastResource,