From 3d7af98ac90dcdbcff4e2871767f64ff24fdd24e Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Wed, 16 Nov 2022 17:16:41 -0500 Subject: [PATCH] fix(auth): add sort of mutex on onAuthChanges callback trigger --- .../repositories/authentication_repository_impl.dart | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/wyatt_authentication_bloc/lib/src/data/repositories/authentication_repository_impl.dart b/packages/wyatt_authentication_bloc/lib/src/data/repositories/authentication_repository_impl.dart index 58196fe7..5904d2a4 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/repositories/authentication_repository_impl.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/repositories/authentication_repository_impl.dart @@ -44,6 +44,8 @@ class AuthenticationRepositoryImpl final OnAuthChange? _onAccountChanges; + bool _pause = false; // Semaphore + AuthenticationRepositoryImpl({ required AuthenticationCacheDataSource authenticationCacheDataSource, required AuthenticationRemoteDataSource authenticationRemoteDataSource, @@ -120,6 +122,7 @@ class AuthenticationRepositoryImpl }) => Result.tryCatchAsync( () async { + _pause = true; final account = await _authenticationRemoteDataSource.signUp( email: email, password: password, @@ -135,9 +138,13 @@ class AuthenticationRepositoryImpl (error) async => error, ); } + _pause = false; return account; }, - (error) => error, + (error) { + _pause = false; + return error; + }, ); @override @@ -200,7 +207,7 @@ class AuthenticationRepositoryImpl @override Stream>> 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)); }