Skip to content

Instantly share code, notes, and snippets.

@mayojava
Created November 7, 2018 18:45
Show Gist options
  • Select an option

  • Save mayojava/cb1d9ecc6389f1faa7bf2293d2d1ae34 to your computer and use it in GitHub Desktop.

Select an option

Save mayojava/cb1d9ecc6389f1faa7bf2293d2d1ae34 to your computer and use it in GitHub Desktop.
Receiving from a channel
fun main() = runBlocking<Unit> {
val channel = Channel<Int>()
launch {
for (i in 1..5) {
channel.send(i)
}
channel.close()
}
for (i in channel) {
println("received: $i")
}
}
//console output
received: 1
received: 2
received: 3
received: 4
received: 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment