refactor: make sure ensureNotSoftLoggedOut does not run multiple times
This commit is contained in:
parent
3f8a4c8189
commit
5a79aa9536
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue