Fixed
Status Update
Comments
hu...@littlerobots.nl <hu...@littlerobots.nl> #2
Yigit, do you have time to fix it?
reemission of the same liveData is racy
reemission of the same liveData is racy
il...@google.com <il...@google.com>
hu...@littlerobots.nl <hu...@littlerobots.nl> #3
yea i'll take it.
ap...@google.com <ap...@google.com> #4
Thanks for the detailed analysis. This may not be an issue anymore since we've started using Main.immediate there but I' not sure; I'll try to create a test case.
ap...@google.com <ap...@google.com> #5
just emitting same live data reproduces the issue.
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
ap...@google.com <ap...@google.com> #6
With 2.2.0-alpha04 (that use Main.immediate), the issue seems to be still there (I tested it by calling emitSource() twice, like your test case)
Description
Version used: 1.0.0-alpha07
The OnBackPressedDispatcher should be able to tell at any point what OnBackPressedCallback is enabled or disabled without polling isEnabled() to get a just-in-time answer. This avoids the issue with the current onBackPressed() logic where the system doesn't know what onBackPressed() will do until you actually press the button.
This implies that all callbacks should be calling setEnabled() at the appropriate times to enable or disable them based on their own internal state changing. To enforce this behavior, setEnabled() and isEnabled() should be final.