Ivan Pavlov
06/03/2020, 5:36 PMval channel = BroadcastChannel<Event>(10)
val receiveChannel = channel.openSubscription()
val flow = receiveChannel.consumeAsFlow()
flow.onEach(someProcessor::doOnEach)
.catch { log.error(it) { "Error while processing event" } }
.launchIn(coroutineScope)
In my case I have to just skip an event if an exception is thrown in someProcessor.doOnEach(event: Event)
and continue processing of next events.
I can achieve what I want with
flow.onEach {
try {
someProcessor.doOnEach(it)
} catch (e: Throwable) {
//log
}
}
but I feel like I'm missing something. Is there a better way to do this?octylFractal
06/03/2020, 5:36 PMIvan Pavlov
06/03/2020, 5:40 PMDominaezzz
06/03/2020, 6:54 PMFlow
doesn't really handle exceptions like that, as it wouldn't be "transparent" as the docs put it.Dominaezzz
06/03/2020, 6:59 PM