IntermediateFlow

SharedFlow Event

Emit a one-time event with SharedFlow.

Dependency required: implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
kotlin
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*

fun main() = runBlocking {
    val events = MutableSharedFlow<String>()
    launch { events.collect { println(it) } }
    delay(20)
    events.emit("Saved")
    delay(50)
}
Output
Saved

Explanation

emit sends to collectors. SharedFlow is hot — suitable for events.