Loading packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/DeferScope.kt +14 −18 Original line number Diff line number Diff line Loading @@ -22,10 +22,8 @@ internal interface DeferScope { fun <R> deferAsync(block: () -> R): Lazy<R> } internal inline fun <A> deferScope(block: DeferScope.() -> A): A { val scope = object : DeferScope { val deferrals = ArrayDeque<() -> Unit>() // TODO: store lazies instead? internal class DeferScopeImpl : DeferScope { val deferrals = ArrayDeque<() -> Unit>() fun drainDeferrals() { while (deferrals.isNotEmpty()) { Loading @@ -40,10 +38,6 @@ internal inline fun <A> deferScope(block: DeferScope.() -> A): A { override fun <R> deferAsync(block: () -> R): Lazy<R> = lazy(block).also { deferrals.add { it.value } } } return scope.block().also { scope.drainDeferrals() } } internal object NoValue internal class CompletableLazy<T>( private var _value: Any? = NoValue, Loading @@ -63,4 +57,6 @@ internal class CompletableLazy<T>( } override fun isInitialized(): Boolean = _value !== NoValue private object NoValue } packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/Network.kt +5 −3 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ internal class Network(val coroutineScope: CoroutineScope, val coalescingPolicy: } override val transactionStore = TransactionStore() private val deferScopeImpl = DeferScopeImpl() private val stateWrites = ArrayDeque<StateSource<*>>() private val fastOutputs = ArrayDeque<Output<*>>() private val outputsByDispatcher = Loading Loading @@ -182,8 +183,9 @@ internal class Network(val coroutineScope: CoroutineScope, val coalescingPolicy: onResult.invokeOnCompletion { job.cancel() } } inline fun <R> evalScope(block: EvalScope.() -> R): R = deferScope { block(EvalScopeImpl(this@Network, this)) inline fun <R> evalScope(block: EvalScope.() -> R): R = block(EvalScopeImpl(networkScope = this, deferScope = deferScopeImpl)).also { deferScopeImpl.drainDeferrals() } /** Performs a transactional update of the Kairos network. */ Loading Loading
packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/DeferScope.kt +14 −18 Original line number Diff line number Diff line Loading @@ -22,10 +22,8 @@ internal interface DeferScope { fun <R> deferAsync(block: () -> R): Lazy<R> } internal inline fun <A> deferScope(block: DeferScope.() -> A): A { val scope = object : DeferScope { val deferrals = ArrayDeque<() -> Unit>() // TODO: store lazies instead? internal class DeferScopeImpl : DeferScope { val deferrals = ArrayDeque<() -> Unit>() fun drainDeferrals() { while (deferrals.isNotEmpty()) { Loading @@ -40,10 +38,6 @@ internal inline fun <A> deferScope(block: DeferScope.() -> A): A { override fun <R> deferAsync(block: () -> R): Lazy<R> = lazy(block).also { deferrals.add { it.value } } } return scope.block().also { scope.drainDeferrals() } } internal object NoValue internal class CompletableLazy<T>( private var _value: Any? = NoValue, Loading @@ -63,4 +57,6 @@ internal class CompletableLazy<T>( } override fun isInitialized(): Boolean = _value !== NoValue private object NoValue }
packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/Network.kt +5 −3 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ internal class Network(val coroutineScope: CoroutineScope, val coalescingPolicy: } override val transactionStore = TransactionStore() private val deferScopeImpl = DeferScopeImpl() private val stateWrites = ArrayDeque<StateSource<*>>() private val fastOutputs = ArrayDeque<Output<*>>() private val outputsByDispatcher = Loading Loading @@ -182,8 +183,9 @@ internal class Network(val coroutineScope: CoroutineScope, val coalescingPolicy: onResult.invokeOnCompletion { job.cancel() } } inline fun <R> evalScope(block: EvalScope.() -> R): R = deferScope { block(EvalScopeImpl(this@Network, this)) inline fun <R> evalScope(block: EvalScope.() -> R): R = block(EvalScopeImpl(networkScope = this, deferScope = deferScopeImpl)).also { deferScopeImpl.drainDeferrals() } /** Performs a transactional update of the Kairos network. */ Loading