hard20 pts · first answer countskotlin-flowkotlin-coroutines
Collecting a cold Flow twice
What does this Kotlin program print, one value per line?
val numbers = flow {
println("start")
emit(1)
emit(2)
}
fun main() = runBlocking {
numbers.collect { println(it) }
numbers.take(1).collect { println(it) }
}Discussion 0
Join free to post in the discussion.
Related questions
- launch vs async in coroutinesMobile App Developer
- Exposing UI state from a ViewModelMobile App Developer
- collectAsStateWithLifecycle benefitMobile App Developer
- viewModelScope after the screen closesMobile App Developer
- Blocking file read in a coroutineMobile App Developer
- Room DAO returning a FlowMobile App Developer
- Polling loop that ignores cancellationMobile App Developer
- One failing request in coroutineScopeMobile App Developer