Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumKotlinFlow cold streamsSingle-choice MCQ

What does this code print, where `take(2)` is applied to an infinite cold flow?

import kotlinx.coroutines.flow.* val infinite = flow { var i = 0 while (true) { println("emitting $i") emit(i++) } } suspend fun run() { infinite.take(2).collect { println("got $it") } }