Merge "Use a SupervisorJob in BubbleDataRepository" into udc-qpr-dev am: 4ed855afcd

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23766624

Change-Id: Icfa9751c329b3cff0534cfaad7f6d6639750efa3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2023-06-22 23:27:06 +00:00
committed by Automerger Merge Worker

View File

@@ -33,6 +33,7 @@ import com.android.wm.shell.common.ShellExecutor
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancelAndJoin import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.yield import kotlinx.coroutines.yield
@@ -45,7 +46,7 @@ internal class BubbleDataRepository(
private val volatileRepository = BubbleVolatileRepository(launcherApps) private val volatileRepository = BubbleVolatileRepository(launcherApps)
private val persistentRepository = BubblePersistentRepository(context) private val persistentRepository = BubblePersistentRepository(context)
private val ioScope = CoroutineScope(Dispatchers.IO) private val coroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
private var job: Job? = null private var job: Job? = null
// For use in Bubble construction. // For use in Bubble construction.
@@ -131,7 +132,7 @@ internal class BubbleDataRepository(
*/ */
private fun persistToDisk() { private fun persistToDisk() {
val prev = job val prev = job
job = ioScope.launch { job = coroutineScope.launch {
// if there was an ongoing disk I/O operation, they can be cancelled // if there was an ongoing disk I/O operation, they can be cancelled
prev?.cancelAndJoin() prev?.cancelAndJoin()
// check for cancellation before disk I/O // check for cancellation before disk I/O
@@ -148,7 +149,7 @@ internal class BubbleDataRepository(
* bubbles. * bubbles.
*/ */
@SuppressLint("WrongConstant") @SuppressLint("WrongConstant")
fun loadBubbles(userId: Int, cb: (List<Bubble>) -> Unit) = ioScope.launch { fun loadBubbles(userId: Int, cb: (List<Bubble>) -> Unit) = coroutineScope.launch {
/** /**
* Load BubbleEntity from disk. * Load BubbleEntity from disk.
* e.g. * e.g.