dave08
02/20/2023, 3:46 PMcoroutineScope { } in a suspend function, do I need to put the either { } outside or inside of it (does it matter)? Or maybe there's a variant of either { } that does that?simon.vergauwen
02/20/2023, 3:51 PMeither is inside coroutineScope then it can never cancel the coroutineScope.
coroutineScope {
either<String, Int> {
launch { delay(1_000_000) }
ensureNotNull(null) { "Fails" }
} // Either.Left("Fails")
} // waits 1_000_000 completion
If you either is outside of coroutineScope it can cancel or short-circuit the coroutineScope.
either<String, Int> {
coroutineScope {
launch { delay(1_000_000) }
ensureNotNull(null) { "Fails" }
} // Finishes "immediately", and cancels delay
} // Either.Left("Fails")