https://kotlinlang.org logo
#coroutines
Title
# coroutines
g

ghedeon

03/21/2019, 7:56 AM
How to wrap
Deffered
into another
Deferred
with a custom exception? There is no coroutine context in that place, so I can't use
.await()
Ok, seems like this is working:
Copy code
val wrapper = CompletableDeferred<RESPONSE>()
val source: CompletableDeferred<RESPONSE> = ...
source.invokeOnCompletion(handler = {
    val ex = source.getCompletionExceptionOrNull()
    if (ex != null) wrapper.completeExceptionally(ex.wrap())
    else wrapper.complete(source.getCompleted())
})
2 Views