Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee17dec5 authored by Devarshi Bhatt's avatar Devarshi Bhatt Committed by Android (Google) Code Review
Browse files

Merge "Run kotlin CallbackFlow on background dispatcher." into main

parents 3070bccf 06fefe18
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.withContext
@@ -518,6 +519,7 @@ class CustomizationProviderClientImpl(
                awaitClose { context.contentResolver.unregisterContentObserver(observer) }
            }
            .onStart { emit(Unit) }
            .flowOn(backgroundDispatcher)
    }

    private fun String.toIntent(
+20 −18
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext
import kotlinx.coroutines.flow.flowOn

/** Utility class that could give information about if animation are enabled in the system */
interface AnimationStatusRepository {
@@ -45,8 +45,9 @@ constructor(
     * Emits true if animations are enabled in the system, after subscribing it immediately emits
     * the current state
     */
    override fun areAnimationsEnabled(): Flow<Boolean> = conflatedCallbackFlow {
        val initialValue = withContext(backgroundDispatcher) { resolver.areAnimationsEnabled() }
    override fun areAnimationsEnabled(): Flow<Boolean> =
        conflatedCallbackFlow {
                val initialValue = resolver.areAnimationsEnabled()
                trySend(initialValue)

                val observer =
@@ -65,4 +66,5 @@ constructor(

                awaitClose { resolver.unregisterContentObserver(observer) }
            }
            .flowOn(backgroundDispatcher)
}