aboutsummaryrefslogtreecommitdiffstats
path: root/integration/kotlinx-coroutines-guava/src/ListenableFuture.kt
diff options
context:
space:
mode:
Diffstat (limited to 'integration/kotlinx-coroutines-guava/src/ListenableFuture.kt')
-rw-r--r--integration/kotlinx-coroutines-guava/src/ListenableFuture.kt8
1 files changed, 5 insertions, 3 deletions
diff --git a/integration/kotlinx-coroutines-guava/src/ListenableFuture.kt b/integration/kotlinx-coroutines-guava/src/ListenableFuture.kt
index 53019c4b..8f11e0a9 100644
--- a/integration/kotlinx-coroutines-guava/src/ListenableFuture.kt
+++ b/integration/kotlinx-coroutines-guava/src/ListenableFuture.kt
@@ -136,11 +136,13 @@ public fun <T> ListenableFuture<T>.asDeferred(): Deferred<T> {
override fun onSuccess(result: T?) {
// Here we work with flexible types, so we unchecked cast to trick the type system
@Suppress("UNCHECKED_CAST")
- deferred.complete(result as T)
+ runCatching { deferred.complete(result as T) }
+ .onFailure { handleCoroutineException(EmptyCoroutineContext, it) }
}
override fun onFailure(t: Throwable) {
- deferred.completeExceptionally(t)
+ runCatching { deferred.completeExceptionally(t) }
+ .onFailure { handleCoroutineException(EmptyCoroutineContext, it) }
}
}, MoreExecutors.directExecutor())
@@ -299,7 +301,7 @@ private class ToContinuation<T>(
*/
private class ListenableFutureCoroutine<T>(
context: CoroutineContext
-) : AbstractCoroutine<T>(context) {
+) : AbstractCoroutine<T>(context, initParentJob = true, active = true) {
// JobListenableFuture propagates external cancellation to `this` coroutine. See JobListenableFuture.
@JvmField