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

dave08

10/18/2018, 3:43 PM
I have a
produce { }
that sends download status to a notification service, so if there's an exceoption I'd like to be able to send an error message. It looks like
try { } catch() { }
is unreliable (https://github.com/Kotlin/kotlinx.coroutines/issues/361), and installing a
CoroutineExceptionHandler
on
produce
I won't be able to get to its channel to report status... is there any better way to do this?
v

Vsevolod Tolstopyatov [JB]

10/18/2018, 3:58 PM
produce
already does what you want:
Uncaught exceptions in this coroutine close the channel with this exception as a cause and the resulting channel becomes failed, so that any attempt to receive from such a channel throws exception.
and after failure you cannot send “regular” message, because
produce
has the same lifecycle as its channel
2 Views