Last active
November 7, 2018 18:56
-
-
Save mayojava/80387c6355eb5e86495dee040d1daa7c to your computer and use it in GitHub Desktop.
Produce builder sample
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 { | |
val multiplesOfThree = produce { | |
(1..10).filter { | |
it % 3 == 0 | |
}.forEach { | |
send(it) //send can only be called inside the ProducerScope | |
} | |
} | |
multiplesOfThree.consumeEach { | |
println(it) | |
} | |
} | |
//console output | |
3 | |
6 | |
9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment