I want to select between 2 `Deferred<V>` but...
# coroutines
k
I want to select between 2
Deferred<V>
but only fail if both fail. Would this work/is there a better way to do it?
d
What do you mean by fail? Cancellation or thrown error?
For the latter, you should make sure to start them in a
supervisorScope {}
k
They are completabledeferred, when I asked the question I meant completedexceptionally
o
personally I would do:
Copy code
select<Int> {
                t.onJoin {
                    try {
                        t.await()
                    } catch (e: Exception) {
                        o.await()
                    }
                }
                o.onJoin {
                    try {
                        o.await()
                    } catch (e: Exception) {
                        t.await()
                    }
                }
            }
with the try-catch probably pulled out to a function
👍 1
d
I'd make sure to add some logic for suppressed exceptions as well.
o
yes, probably another try-catch around the second
await
. more reasons to make it its own function 🙂
d
Or just some logic with
if (isCompletedExceptionally)