1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.kairos 18 19 import kotlin.coroutines.RestrictsSuspension 20 import kotlinx.coroutines.CoroutineScope 21 22 /** 23 * Scope for external side-effects triggered by the Frp network. This still occurs within the 24 * context of a transaction, so general suspending calls are disallowed to prevent blocking the 25 * transaction. You can use [frpCoroutineScope] to [launch] new coroutines to perform long-running 26 * asynchronous work. This scope is alive for the duration of the containing [FrpBuildScope] that 27 * this side-effect scope is running in. 28 */ 29 @RestrictsSuspension 30 @ExperimentalFrpApi 31 interface FrpEffectScope : FrpTransactionScope { 32 /** 33 * A [CoroutineScope] whose lifecycle lives for as long as this [FrpEffectScope] is alive. This 34 * is generally until the [Job] returned by [FrpBuildScope.effect] is cancelled. 35 */ 36 @ExperimentalFrpApi val frpCoroutineScope: CoroutineScope 37 38 /** 39 * A [FrpNetwork] instance that can be used to transactionally query / modify the FRP network. 40 * 41 * The lambda passed to [FrpNetwork.transact] on this instance will receive an [FrpBuildScope] 42 * that is lifetime-bound to this [FrpEffectScope]. Once this [FrpEffectScope] is no longer 43 * alive, any modifications to the FRP network performed via this [FrpNetwork] instance will be 44 * undone (any registered [observers][FrpBuildScope.observe] are unregistered, and any pending 45 * [side-effects][FrpBuildScope.effect] are cancelled). 46 */ 47 @ExperimentalFrpApi val frpNetwork: FrpNetwork 48 } 49