Hey Simon, in my exact use case I have just a single value that I’m expecting from the flow (along with the possible cancellations/failures). The code snippet that I used was illustrative
s
simon.vergauwen
09/05/2022, 12:34 PM
If you're only expecting a single value, why not use
suspend fun
with
suspendCoroutineCancellable
? Then you could do something like:
Copy code
either<Error, Res> {
val res: Res = guaranteeCase({ action() }) { exitCase ->
when(exitCase) {
ExitCase.Completed -> Unit
ExitCase.Failure -> Unit
ExitCase.Cancelled -> shift(FlowError.Canceled(it.message ?: ""))
}
}
}
simon.vergauwen
09/05/2022, 12:35 PM
Or
Copy code
either<Error, Res> {
val res: Res = onCancel({ action() }) {
shift(..)
}
}