Skip to content

Instantly share code, notes, and snippets.

@kevalpatel2106
Created July 19, 2021 07:40
Show Gist options
  • Save kevalpatel2106/5f35a829169f6a427a697e611656e254 to your computer and use it in GitHub Desktop.
Save kevalpatel2106/5f35a829169f6a427a697e611656e254 to your computer and use it in GitHub Desktop.
Kotlin channel types demo
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