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

Commit 5c09b43a authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[kairos] Drop old Jobs in MutableEvents.emit" into main

parents fccc7df2 d2b22f7c
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)
        }
    }
}