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

Commit be58e91c authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Introduce @Background CoroutineScope

Follow up from go/bg-flow: this adds a background application scope, that is essentially the application scope with a bg context by default.

Flag: None
Test: DisplayRepositoryTest
Fixes: 313411258
Change-Id: I452608172484b8f89e9137442eec4fda2984ae6c
parent 73330b61
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ constructor(
    private val displayManager: DisplayManager,
    @Background backgroundHandler: Handler,
    @Application applicationScope: CoroutineScope,
    @Background bgApplicationScope: CoroutineScope,
    @Background backgroundCoroutineDispatcher: CoroutineDispatcher
) : DisplayRepository {
    private val allDisplayEvents: Flow<DisplayEvent> =
@@ -203,9 +204,8 @@ constructor(
            }
            .distinctUntilChanged()
            .debugLog("connectedDisplayIds")
            .flowOn(backgroundCoroutineDispatcher)
            .stateIn(
                applicationScope,
                bgApplicationScope,
                started = SharingStarted.WhileSubscribed(),
                // The initial value is set to empty, but connected displays are gathered as soon as
                // the flow starts being collected. This is to ensure the call to get displays (an
+9 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.plus
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext

@@ -27,6 +28,14 @@ class CoroutinesModule {
            @Main dispatcherContext: CoroutineContext,
    ): CoroutineScope = CoroutineScope(dispatcherContext)

    @Provides
    @SysUISingleton
    @Background
    fun bgApplicationScope(
            @Application applicationScope: CoroutineScope,
            @Background coroutineContext: CoroutineContext,
    ): CoroutineScope = applicationScope.plus(coroutineContext)

    @Provides
    @SysUISingleton
    @Main
+1 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ class DisplayRepositoryTest : SysuiTestCase() {
                displayManager,
                testHandler,
                TestScope(UnconfinedTestDispatcher()),
                TestScope(UnconfinedTestDispatcher()),
                UnconfinedTestDispatcher()
            )
        verify(displayManager, never()).registerDisplayListener(any(), any())