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

Commit 4da10276 authored by Andreas Miko's avatar Andreas Miko
Browse files

Remove Nothing return from onActivated()

The `activate()` function returns Nothing as it is the API surface and
it communicates to the user that the function never returns.
`onActivated()` in turn is only called internally and is supposed to
be overriden. Returning Nothing forces the overwrite to add
`awaitCancellation` which is unnecessary because it is ok to make it
return early.

Bug: b/420591935
Test: Refactor only
Flag: com.android.systemui.scene_container
Change-Id: Ie1541f303e4930f36775b8e88d3b43dfbde6d95e
parent 824e843a
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.lifecycle

import java.util.concurrent.atomic.AtomicBoolean
import kotlinx.coroutines.awaitCancellation

/**
 * A base [Activatable] that can only be activated by a single owner (hence "exclusive"). A previous
@@ -41,6 +42,7 @@ abstract class ExclusiveActivatable : Activatable {
            onActivated()
        } finally {
            isActive = false
            awaitCancellation()
        }
    }

@@ -56,17 +58,16 @@ abstract class ExclusiveActivatable : Activatable {
     *
     * Implementations could follow this pattern:
     * ```kotlin
     * override suspend fun onActivated(): Nothing {
     * override suspend fun onActivated() {
     *     coroutineScope {
     *         launch { ... }
     *         launch { ... }
     *         launch { ... }
     *         awaitCancellation()
     *     }
     * }
     * ```
     *
     * @see activate
     */
    protected abstract suspend fun onActivated(): Nothing
    protected abstract suspend fun onActivated()
}
+3 −5
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ abstract class HydratedActivatable : Activatable {
        coroutineScope {
            launch { hydrator.activate() }
            onActivated()
            awaitCancellation()
        }
    }

@@ -56,21 +57,18 @@ abstract class HydratedActivatable : Activatable {
     *
     * Implementations could follow this pattern:
     * ```kotlin
     * override suspend fun onActivated(): Nothing {
     * override suspend fun onActivated() {
     *     coroutineScope {
     *         launch { ... }
     *         launch { ... }
     *         launch { ... }
     *         awaitCancellation()
     *     }
     * }
     * ```
     *
     * @see activate
     */
    protected open suspend fun onActivated(): Nothing {
        awaitCancellation()
    }
    protected open suspend fun onActivated() {}

    /** @see [Hydrator.hydratedStateOf] */
    protected fun <T> StateFlow<T>.hydratedStateOf(traceName: String): State<T> =