fix(auth): add sort of mutex on onAuthChanges callback trigger
This commit is contained in:
parent
b033b97917
commit
3d7af98ac9
@ -44,6 +44,8 @@ class AuthenticationRepositoryImpl<T extends Object>
|
||||
|
||||
final OnAuthChange<T>? _onAccountChanges;
|
||||
|
||||
bool _pause = false; // Semaphore
|
||||
|
||||
AuthenticationRepositoryImpl({
|
||||
required AuthenticationCacheDataSource<T> authenticationCacheDataSource,
|
||||
required AuthenticationRemoteDataSource authenticationRemoteDataSource,
|
||||
@ -120,6 +122,7 @@ class AuthenticationRepositoryImpl<T extends Object>
|
||||
}) =>
|
||||
Result.tryCatchAsync<Account, AppException, AppException>(
|
||||
() async {
|
||||
_pause = true;
|
||||
final account = await _authenticationRemoteDataSource.signUp(
|
||||
email: email,
|
||||
password: password,
|
||||
@ -135,9 +138,13 @@ class AuthenticationRepositoryImpl<T extends Object>
|
||||
(error) async => error,
|
||||
);
|
||||
}
|
||||
_pause = false;
|
||||
return account;
|
||||
},
|
||||
(error) => error,
|
||||
(error) {
|
||||
_pause = false;
|
||||
return error;
|
||||
},
|
||||
);
|
||||
|
||||
@override
|
||||
@ -200,7 +207,7 @@ class AuthenticationRepositoryImpl<T extends Object>
|
||||
@override
|
||||
Stream<FutureResult<AccountWrapper<T>>> streamAccount() =>
|
||||
_authenticationRemoteDataSource.streamAccount().map((account) async {
|
||||
if (_onAccountChanges.isNotNull) {
|
||||
if (_onAccountChanges.isNotNull && !_pause) {
|
||||
final dataResult = await _onAccountChanges!.call(account);
|
||||
return dataResult.map((data) => AccountWrapperModel(account, data));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user