@Test fun `testing sharing values`() { fun getFlow(myChannel: Channel): Flow = flow { while (true) emit(myChannel.receive()) } runBlocking { val scopeProducer = CoroutineScope(Dispatchers.Default) val scopeFirstConsumer = CoroutineScope(Dispatchers.Default) val scopeSecondConsumer = CoroutineScope(Dispatchers.Default) var counter = 0 val myChannel: Channel = Channel() // Channel producer scopeProducer.launch { while (true) { myChannel.offer(counter++) delay(500) } } // First consumer scopeFirstConsumer.launch { getFlow(myChannel).collect { println("First $it") } } // Second consumer scopeSecondConsumer.launch { getFlow(myChannel).collect { println("Second $it") } } delay(5000) } }