Skip to content

Instantly share code, notes, and snippets.

@mayojava
Last active November 7, 2018 18:56
Show Gist options
  • Save mayojava/80387c6355eb5e86495dee040d1daa7c to your computer and use it in GitHub Desktop.
Save mayojava/80387c6355eb5e86495dee040d1daa7c to your computer and use it in GitHub Desktop.
Produce builder sample
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