<@UCYLEDW3X> ask away!
# arrow
p
@PPWasin ask away!
here!
p
@pakoito On your guideline about cancellation. https://www.pacoworks.com/2019/12/15/kotlin-coroutines-with-arrow-fx/ In this paragraph:
Copy code
It does not check cancellation when suspend functions are calling each other, although that feature will be added on a future release.
So, be mindful when using suspended() because cancellation won't propagate even when called from IO { } or effect { }.
Could you give me more details about it.
p
sure!
Copy code
suspend fun bla() {
  println("paco")
}

suspend fun ble() {
  delay(300)
  bla()
}

val first = IO { ble() }.flatMap { IO { println("peco") } }

IO.raceN(IO.dispatchers().default(), first, IO.just(Unit))
that'd print "paco" but not "peco"
both IOs are started on a race, so the first one to complete cancels the other
the first one calls
ble
, which delays 300ms. Meanwhile the second one completes immediately, triggering the cancellation
cancellation in 0.10 is checked before executing
.flatMap
so
ble
completes the delay and calls
bla
and then hits the cancellation point
p
Isn’t that just the normal behavior of cancellation. Because the IO.just(Unit) finish first.
What I don’t quite understand is
Copy code
cancellation won't propagate
p
on the next iteration, we'll be also able to cancel
ble
calling
bla
after the delay
ooooh
right
Copy code
fun suspend patatas() {
  myIO.suspended()
}
if you cancel that from kotlinx.coroutines' machinery,
myIO
will not be cancelled and will complete
p
Oh I see.
Because It different scope right?
So to fix it I need to run myIO.suspended() In the same scope as the parent.
What I mean fix. Is to make the myIO.suspend also cancel.
p
"Scope" is a kx.coroutines concept
we need an adapter for it, maybe an specialized
suspended
p
Oh ok. That is clear for now I think.
Thank a lot @pakoito
p
no problem 😄 remember to spread the article, that's my only ask
p
Sure 🙂