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

Thiyagu

01/02/2020, 2:01 PM
what is the equivalent of
onErrorContinue
in kotlin flow?
t

Thiyagu

01/02/2020, 2:24 PM
my use case is little bit different here. if an exception in any flow operator, skip the next operator for the elements and continue the pipeline for subsequent elements.
Copy code
fun main() = runBlocking {

    val ints = flow {
        // flow builder
        for (i in 1..10) {
            delay(100)
            emit(i) // emit next value
        }
    }

    ints.map {
        if (it == 5) throw IllegalArgumentException("throwing exception")
        it * 2
    }.catch {
        println("caught exception") // if any exception, don't process the next operator in the pipeline and continue the next subsequent element in the flow.
    }.collect {
        println("received $it")
    }
}
d

Dominaezzz

01/02/2020, 2:25 PM
Ah! This use case. I'll find you a link.
t

Thiyagu

01/02/2020, 2:28 PM
nice 👍 Thanks 🙏
16 Views