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

Commit 771902b5 authored by Bhavuk Jain's avatar Bhavuk Jain
Browse files

Changes to make clocks load in IO dispatcher

This CL aims at making sure that clock loading operations happen in a
seperate IO dispatcher which does not cause the main thread to block
while the clocks are being loaded. We use limited parallelism value as 1
since it allows execution of all clock operations (loading, sending of
events, etc.) in a sequential manner.

Bug: b/312519936
Test: Tested by building and flashing on local, also by adding log
statements and seeing whether all operations are running on same thread
or not, also by perfetto trace.
Flag: N/A

Change-Id: Ibd6ac2fc5bec4d4d6636492dfb04a28344be0914
parent 79c8091d
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.mapNotNull
@@ -65,6 +66,10 @@ class ClockCarouselViewModel(
                    ClockCarouselItemViewModel(it.clockId, it.isSelected, contentDescription)
                }
            }
            // makes sure that the operations above this statement are executed on I/O dispatcher
            // while parallelism limits the number of threads this can run on which makes sure that
            // the flows run sequentially
            .flowOn(backgroundDispatcher.limitedParallelism(1))
            .stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())

    val selectedClockSize: Flow<ClockSize> = interactor.selectedClockSize