https://kotlinlang.org logo
Title
h

Harun

06/14/2019, 5:18 AM
When using callBackflow, what's the correct way of cancellation? 1. Do you close the channel and pass it the exception? 2. Do you cancel the scope and provide a CancellationException?
e

elizarov

06/14/2019, 5:27 AM
Depends on the reason (initiator) of cancellation. The data source would close the channel when the data is over. The data consumer would cancel its scope when it does not want more data.
h

Harun

06/14/2019, 5:36 AM
I want the exception to be passed to the callers. I have a callback based API and I want to return values as a Flow. When the result is a failure I want to cancel the job and pass the exception that caused the failure I want to know the proper way of cancelling a Coroutine in callbackFlow in that scenario
e

elizarov

06/14/2019, 5:37 AM
If you are writing a data producer then you close the channel with your exception.
h

Harun

06/14/2019, 5:55 AM
Thanks for the clarification