Created
July 19, 2021 07:40
-
-
Save kevalpatel2106/5f35a829169f6a427a697e611656e254 to your computer and use it in GitHub Desktop.
Kotlin channel types demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.channels.Channel | |
import kotlinx.coroutines.flow.receiveAsFlow | |
import kotlinx.coroutines.flow.collect | |
import kotlinx.coroutines.launch | |
import kotlinx.coroutines.GlobalScope | |
fun main() { | |
GlobalScope.launch { | |
val channel = Channel<String>(Channel.BUFFERED) // Replace it with RENDEZVOUS and behaviour will change, you won't see ABC printed | |
channel.send("ABC") | |
channel.receiveAsFlow().collect { | |
println(it) | |
} | |
} | |
println("channelTypesDemo finished\n") | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment