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

Commit 60f5dd1b authored by Steve Elliott's avatar Steve Elliott
Browse files

[kairos] fix MutableTFlow backpressure

Previous impl could accidentally conflate emissions.

Flag: EXEMPT unused
Test: atest kairos-tests
Change-Id: Ibb14d99a5be4b86723433c78e40815789959ad6b
parent fb88b527
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -520,16 +520,14 @@ internal constructor(internal val network: Network, internal val impl: InputNode
    @ExperimentalFrpApi
    suspend fun emit(value: T) {
        coroutineScope {
            var jobOrNull: Job? = null
            val newEmit =
                async(start = CoroutineStart.LAZY) {
                    jobOrNull?.join()
                    network.transaction { impl.visit(this, value) }.await()
                }
            val jobOrNull = storage.getAndSet(newEmit)
            if (jobOrNull?.isActive != true) {
            jobOrNull = storage.getAndSet(newEmit)
            newEmit.await()
            } else {
                jobOrNull.join()
            }
        }
    }