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

Commit 437af864 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[kairos] ensure dispatched outputs do not block transaction" into main

parents 21e58de2 36ed8521
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.systemui.kairos.KairosNetwork
import com.android.systemui.kairos.MutableState
import com.android.systemui.kairos.combine
import com.android.systemui.kairos.effect
import com.android.systemui.kairos.launchEffect
import com.android.systemui.lifecycle.repeatWhenAttachedToWindow
import com.android.systemui.lifecycle.repeatWhenWindowIsVisible
import com.android.systemui.plugins.DarkIconDispatcher
@@ -163,7 +164,7 @@ object MobileIconBinderKairos {
        repeatWhenWindowIsVisible(view) {
            logger.logCollectionStarted(view, viewModel)
            binding.isCollecting = true
            effect {
            launchEffect {
                try {
                    awaitCancellation()
                } finally {
+4 −4
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ interface BuildScope : HasNetwork, StateScope {
    // TODO: remove disposable handle return? might add more confusion than convenience
    fun <A> Events<A>.observe(
        coroutineContext: CoroutineContext = EmptyCoroutineContext,
        block: suspend EffectScope.(A) -> Unit,
        block: EffectScope.(A) -> Unit,
    ): DisposableHandle

    /**
@@ -638,7 +638,7 @@ interface BuildScope : HasNetwork, StateScope {
     *
     * With each invocation of [block], running effects from the previous invocation are cancelled.
     */
    fun <A> Events<A>.observeLatest(block: suspend EffectScope.(A) -> Unit): DisposableHandle =
    fun <A> Events<A>.observeLatest(block: EffectScope.(A) -> Unit): DisposableHandle =
        mapLatestBuild { effect { block(it) } }.observeSync()

    /**
@@ -702,7 +702,7 @@ interface BuildScope : HasNetwork, StateScope {
     */
    fun <A> State<A>.observe(
        coroutineContext: CoroutineContext = EmptyCoroutineContext,
        block: suspend EffectScope.(A) -> Unit,
        block: EffectScope.(A) -> Unit,
    ): DisposableHandle =
        now.map { sample() }.mergeWith(changes) { _, new -> new }.observe(coroutineContext, block)

@@ -769,7 +769,7 @@ fun <A> BuildScope.asyncEvent(block: suspend KairosScope.() -> A): Events<A> =
@ExperimentalKairosApi
fun BuildScope.effect(
    context: CoroutineContext = EmptyCoroutineContext,
    block: suspend EffectScope.() -> Unit,
    block: EffectScope.() -> Unit,
): Job = launchScope(context) { now.observe { block() } }

/**
+1 −1
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ internal class BuildScopeImpl(val stateScope: StateScopeImpl, val coroutineScope

    override fun <A> Events<A>.observe(
        coroutineContext: CoroutineContext,
        block: suspend EffectScope.(A) -> Unit,
        block: EffectScope.(A) -> Unit,
    ): DisposableHandle {
        val interceptor = coroutineContext[ContinuationInterceptor]
        return observeInternal(coroutineContext) { effectScope, output ->
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ internal interface NetworkScope : InitScope {

    fun scheduleOutput(output: Output<*>)

    fun scheduleDispatchedOutput(interceptor: ContinuationInterceptor?, block: suspend () -> Unit)
    fun scheduleDispatchedOutput(interceptor: ContinuationInterceptor?, block: () -> Unit)

    fun scheduleMuxMover(muxMover: MuxDeferredNode<*, *, *>)

+2 −3
Original line number Diff line number Diff line
@@ -71,8 +71,7 @@ internal class Network(
    private val deferScopeImpl = DeferScopeImpl()
    private val stateWrites = ArrayDeque<StateSource<*>>()
    private val fastOutputs = ArrayDeque<Output<*>>()
    private val outputsByDispatcher =
        HashMap<ContinuationInterceptor, ArrayDeque<suspend () -> Unit>>()
    private val outputsByDispatcher = HashMap<ContinuationInterceptor, ArrayDeque<() -> Unit>>()
    private val muxMovers = ArrayDeque<MuxDeferredNode<*, *, *>>()
    private val deactivations = ArrayDeque<PushNode<*>>()
    private val outputDeactivations = ArrayDeque<Output<*>>()
@@ -84,7 +83,7 @@ internal class Network(

    override fun scheduleDispatchedOutput(
        interceptor: ContinuationInterceptor?,
        block: suspend () -> Unit,
        block: () -> Unit,
    ) {
        outputsByDispatcher
            .computeIfAbsent(interceptor ?: Dispatchers.Unconfined) { ArrayDeque() }