Fixed
Status Update
Comments
ja...@google.com <ja...@google.com>
ra...@google.com <ra...@google.com>
ap...@google.com <ap...@google.com> #2
Yigit, do you have time to fix it?
reemission of the same liveData is racy
reemission of the same liveData is racy
ap...@google.com <ap...@google.com> #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
val constraints = Constraints.Builder()
.setRequiresCharging(true)
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
The default parameters approach is trivial using a data class and named parameters could be used when being constructed.
data class Constraints(
val requiredNetworkType: NetworkType = NetworkType.NOT_REQUIRED,
val requiresCharging: Boolean = false
)
val constraints = Constraints(requiredNetworkType = NetworkType.METERED)
For converting the builder from java to a more idiomatic Kotlin, we could also write a function that uses a method with a receiver on the builder.
inline fun constraints(builder: Constraints.Builder.() -> Unit): Constraints {
return Constraints.Builder().apply { builder() }.build()
}
val constraints = constraints {
setRequiredNetworkType(NetworkType.CONNECTED)
setRequiresCharging(true)
}
The naming of these could probably be renamed, just a nicer way to write builder like classes in kotlin.