INNER CODE UNIT · Kotlin
LiveDataScopeImpl
M66B/FairEmail · app/src/main/java/androidx/lifecycle/CoroutineLiveData.kt:80
internal class LiveDataScopeImpl<T>(
internal var target: CoroutineLiveData<T>,
context: CoroutineContext,
) : LiveDataScope<T> {
override val latestValue: T?
get() = target.value
// use `liveData` provided context + main dispatcher to communicate with the target
// LiveData. This gives us main thread safety as well as cancellation cooperation
private val coroutineContext = context + Dispatchers.Main.immediate
override suspend fun emitSource(source: LiveData<T>): DisposableHandle =
withContext(coroutineContext) {
return@withContext target.emitSource(source)
}
@SuppressLint("NullSafeMutableLiveData")