If I extend an Observable<>
in RxJava, I can override OnDispose()
, and perform cleaning up such as clearing things for the Garbage Collector.
OnDispose()
is called whenever any subscription to this Observable<>
is disposed of.
However, I can't seem to find anything equivalent for Coroutine Channels.
I am aware of channel.close(), but that is not the same.
Is there some way to propagate either
- suspended coroutine cancellation to the Channel; or
- subscription disposal/cancellation to the Channel?
I assume you talking about
doOnDispose
in RxJava. In this case you are sending elements to the channel and would like to know when the downstream had cancelled the channel. If you structure your producing code in a single function, then you can simply usetry/finally
:If your sending code is spread-out and you'd like to receive a cancellation callback then you can use SendChannel.invokeOnClose