genovich
05/04/2022, 4:34 PMraceN()
probably not handling exceptions in a right way.
According to the conversation I had a year ago, it seems to me that if one of functions will throw an exception, then another will not be cancelled.
Do you have an idea how to check such behaviour?simon.vergauwen
05/05/2022, 12:59 PMraceN
operator. I just read your conversation with Roman, and the canceling is happening after select
.
https://github.com/arrow-kt/arrow/blob/225e16f4f22e9458c1d8fe96ae5aa8242306fe17/ar[…]x-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race2.kt
Here you can see that if Left
wins, then it cancels Right
.simon.vergauwen
05/05/2022, 1:00 PMsimon.vergauwen
05/05/2022, 1:02 PMprobably not handling exceptions in a right way.Oh, exceptions. So if
fa
fails that it cancels fb
? There is indeed test missing for that 🤔
We should definitely write them! They can be written in a similar fashion than the other tests I linked.
If you do write them, please raise a PR for this 🙏genovich
05/05/2022, 1:03 PMsimon.vergauwen
05/05/2022, 1:05 PMval latch = CompletableDeferred<Unit>()
val exitCase = CompletableDeferred<ExitCase>()
val res = Either.catch {
raceN(
{
guaranteeCase({
latch.complete(Unit)
awaitCancellation()
}) { require(exitCase.complete(it)) }
},
{
latch.await()
throw RuntimeException("")
}
)
}
require(res is Either.Left)
require(exitCase.await() is ExitCase.Cancelled)
simon.vergauwen
05/05/2022, 1:05 PMsimon.vergauwen
05/05/2022, 1:06 PMfa
got canceled due to fb
throwing an exception, and the result of raceN
is the exception thrown by fb
.genovich
05/05/2022, 1:12 PMfa
will not be cancelled when fb
will throw an exception.genovich
05/05/2022, 1:14 PMselect
genovich
05/05/2022, 1:15 PMcoroutineScope
works insidegenovich
05/05/2022, 1:15 PMsimon.vergauwen
05/05/2022, 1:35 PMselect
. I don't think select
cancels the other one out of the box. There are some gotchas CoroutineScope
, and depending on the actual implementation of the CoroutineScope
can also behave differently. That's why we prefer higher-level operators as we define in Arrow, then you can ignore these lower-level things.genovich
05/06/2022, 8:46 PMcoroutineScope()
function. I read it’s documentation and it says that all coroutines will be cancelled if one of them throw an exception