https://kotlinlang.org logo
#coroutines
Title
# coroutines
u

ursus

03/29/2021, 9:50 PM
why is this
Copy code
fun intervalFlow(delayMillis: Long): Flow<Int> {
    return flow {
        withContext(Dispatchers.Default) {
            var i = 0
            emit(i)
            while (true) {
                delay(delayMillis)
                emit(++i)
            }
        }
    }
}
wrong -- I mean I read the article, but at runtime it doesnt crash, and printing threads in each step, seems correct
l

louiscad

03/30/2021, 9:12 AM
It's explained in the docs. Solution is to use
flowOn
or replace
flow
with
channelFlow
.
3 Views