-
Notifications
You must be signed in to change notification settings - Fork 612
FirebaseDataConnectImpl.kt: use MutableStateFlow to store state, rather than mutexes #6861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FirebaseDataConnectImpl.kt: use MutableStateFlow to store state, rather than mutexes #6861
Conversation
…f AtomicReference
…DataConnect.awaitAuthReady() and FirebaseDataConnect.awaitAppCheckReady()
…w.compareAndSet() directly for improved readability and less potential for bugs
…aconnect/MutableStateFlowUseUpdateInsteadOfCompareAndSet
…dateInsteadOfCompareAndSet
…dateInsteadOfCompareAndSet
Coverage Report 1Affected Products
Test Logs |
Test Results 66 files - 120 66 suites - 120 1m 19s ⏱️ - 3m 15s Results for commit b8f0fc2. ± Comparison against base commit fda3351. This pull request removes 1235 and adds 552 tests. Note that renamed tests count towards both.
This pull request removes 16 skipped tests and adds 1 skipped test. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
Size Report 1Affected Products
Test Logs |
…teInsteadOfCompareAndSet
…irebaseDataConnectImplState
Vertex AI Mock Responses Check
|
…teInsteadOfCompareAndSet
…teInsteadOfCompareAndSet
…CompareAndSet' into dconeybe/dataconnect/FirebaseDataConnectImplState
…irebaseDataConnectImplState
…efresh() to avoid unintentional internal state corruption. This was suggested by Copilot: #6840 (review)
…irebaseDataConnectImplState
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
...-dataconnect/src/main/kotlin/com/google/firebase/dataconnect/core/FirebaseDataConnectImpl.kt
Show resolved
Hide resolved
📝 PRs merging into main branchOur main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the FirebaseDataConnect implementation to replace mutex-based lazy initializations with a state managed by MutableStateFlow, thereby simplifying synchronization and state management. Key changes include replacing SuspensingLazy properties with direct state flow properties, updating tests to use the new queryManager and grpcClient properties instead of lazy wrappers, and refactoring the close logic to align with the new state management.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
QueryRefImplUnitTest.kt | Updated lazyQueryManager usage to queryManager for executing queries. |
MutationRefImplUnitTest.kt | Updated lazyGrpcClient usage to grpcClient for executing mutations. |
QuerySubscriptionImpl.kt | Updated subscription logic to retrieve queryManager from the new state flow. |
QueryRefImpl.kt | Modified execute() method to use queryManager instead of lazyQueryManager. |
MutationRefImpl.kt | Modified execute() method to use grpcClient instead of lazyGrpcClient. |
FirebaseDataConnectImpl.kt | Replaced mutex-based lazy initialization with a MutableStateFlow–based state model and refactored the close logic accordingly. |
Comments suppressed due to low confidence (1)
firebase-dataconnect/src/main/kotlin/com/google/firebase/dataconnect/core/FirebaseDataConnectImpl.kt:181
- [nitpick] Consider improving the error message to provide more context or refactor the state handling logic to prevent reaching an unexpected state, which can aid in debugging.
throw IllegalStateException("newState should be Initialized, but got New (error code sh2rf4wwjx)")
Using MutableStateFlow to store the state of the FirebaseDataConnectImpl greatly simplifies the overall logic since the state is quite complicated and the state and state transitions are represented very naturally this way.