https://kotlinlang.org logo
#feed
Title
z

zsmb

03/08/2020, 7:41 AM
I wrote a bit about coroutine cancellation earlier this week: https://zsmb.co/coroutine-cancellation-101/
❤️ 6
👍 2
r

raulraja

03/08/2020, 11:02 AM
This is great, it may be worth mentioning alternatives. In Arrow Fx cancelation is not cooperative but automatic. Additionally there is an idea that the cancelation primitives should be part of the std lib suspend intrinsics and not just implemented in KotlinX coroutines so different libraries that implement suspension can interoperate in cancelation.
Cooperative cancelation is up to user discipline with KotlinX but it can be wired automatically
a

Ahmed Ibrahim

03/08/2020, 11:17 AM
@zsmb Thanks a lot for this informative blog post. However one follow up question, how far you should go to achieve this cooperative-ness? because one drawback of this is that your code will be full of
ensureActive
or
if (isActive)
calls.
r

raulraja

03/08/2020, 11:56 AM
@zsmb thanks for the article! Here is a gist that demonstrates automatic cancellation. https://gist.github.com/raulraja/d289db68db94462bfc03811a76810d66 These examples where created by @simon.vergauwen and demonstrate how Arrow Fx wires cancellation checks across flatMap boundaries to ensure all dependent fibers are cancelled and no resources are wasted when your operation is composed of a large number of async and concurrent task. Cancellation also transports exceptions in fibers back to the caller inside IO to ensure you can wire safe resource handling when acquiring resources async that may be used in different context but they need to be released regardless of where exceptions happen.
2 Views