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

Commit d2b22f7c authored by Steve Elliott's avatar Steve Elliott
Browse files

[kairos] Drop old Jobs in MutableEvents.emit

Flag: com.android.systemui.status_bar_mobile_icon_kairos
Bug: 383172066
Test: atest
Change-Id: I9adb183c9e274b56e6ab56c2da23ec8b19ee3e58
parent 570cc3f1
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -42,8 +42,8 @@ import java.util.concurrent.atomic.AtomicReference
import kotlin.reflect.KProperty
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch

/**
 * A series of values of type [A] available at discrete points in time.
@@ -352,12 +352,14 @@ internal constructor(
        coroutineScope {
            var jobOrNull: Job? = null
            val newEmit =
                async(start = CoroutineStart.LAZY) {
                launch(start = CoroutineStart.LAZY) {
                    jobOrNull?.join()
                    jobOrNull = null
                    network.transaction("MutableEvents.emit") { impl.visit(this, value) }.await()
                }
            jobOrNull = storage.getAndSet(newEmit)
            newEmit.await()
            newEmit.join()
            storage.compareAndExchange(newEmit, null)
        }
    }
}