refactor: make sure ensureNotSoftLoggedOut does not run multiple times

This commit is contained in:
Krille 2024-05-02 15:43:26 +02:00
parent 3f8a4c8189
commit 5a79aa9536
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652
1 changed files with 15 additions and 9 deletions

View File

@ -1823,10 +1823,13 @@ class Client extends MatrixApi {
return; return;
} }
Future<void>? _handleSoftLogoutFuture;
Future<void> _handleSoftLogout() async { Future<void> _handleSoftLogout() async {
final onSoftLogout = this.onSoftLogout; final onSoftLogout = this.onSoftLogout;
if (onSoftLogout == null) return; if (onSoftLogout == null) return;
_handleSoftLogoutFuture ??= () async {
onLoginStateChanged.add(LoginState.softLoggedOut); onLoginStateChanged.add(LoginState.softLoggedOut);
try { try {
await onSoftLogout(this); await onSoftLogout(this);
@ -1836,6 +1839,9 @@ class Client extends MatrixApi {
await clear(); await clear();
rethrow; rethrow;
} }
}();
await _handleSoftLogoutFuture;
_handleSoftLogoutFuture = null;
} }
/// Checks if the token expires in under [expiresIn] time and calls the /// Checks if the token expires in under [expiresIn] time and calls the