Created
April 5, 2020 13:19
-
-
Save manoamaro/140505673052e13def45c3994a3e7867 to your computer and use it in GitHub Desktop.
kt-coroutines-flow-01
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 randomIntFlow(): Flow<Int> = flow { //flow builder | |
// suspend functions can be called from inside the flow | |
for (i in 1..10) { | |
emit(Random.nextInt()) // emit the value | |
delay(1000) //suspend function | |
} | |
} | |
runBlocking { | |
randomIntFlow().collect { i -> println(i) } // collect() is a suspend function. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment