SharedFlow

Just a managed channel between two coroutines

fun example1QueueBetweenCoroutines(){
        val flow = MutableSharedFlow<Int>()

        runBlocking {
            launch {
                (1 .. 10).forEach{
                    flow.emit(it)
                    delay(500)
                }
            }

            launch {
                delay(1000)
                flow.collect{
                    println("received $it")
                }
            }
        }
    }

Last updated

Was this helpful?