I have a `produce { }` that sends download status ...
# coroutines
d
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
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