Created
November 7, 2018 18:45
-
-
Save mayojava/cb1d9ecc6389f1faa7bf2293d2d1ae34 to your computer and use it in GitHub Desktop.
Receiving from a channel
This file contains hidden or 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
| 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