Is there a way to register a cancellation listener...
# coroutines
v
Is there a way to register a cancellation listener on a coroutine scope without doing
suspendCancellableCoroutine
so that if the scope gets cancelled I can close my DB statements
b
You can use try-finally/`.use` ext to close resources. But if you need a scope callback - you can take Job element from scope and then use invokeOnClose
v
I ended up spinning up a new coroutine in same scope and then hooked up
suspendCancellableCoroutine
b
if scope was cancelled before you launched it - your resource will leak, because coroutine won't be even launched (for this case you need to use non-default
start
option - either Atomic or Undispatched)