From 9f7c3f157101812d84e783446662d8a0a2fa40ab Mon Sep 17 00:00:00 2001 From: TocnoWamGovoriyYaNeHacer201145 Date: Sun, 9 Nov 2025 19:30:22 +0300 Subject: [PATCH] Refactor guava integration with improved error handling --- .../src/ListenableFuture.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/integration/kotlinx-coroutines-guava/src/ListenableFuture.kt b/integration/kotlinx-coroutines-guava/src/ListenableFuture.kt index ea9addc68a..205c5d55e2 100644 --- a/integration/kotlinx-coroutines-guava/src/ListenableFuture.kt +++ b/integration/kotlinx-coroutines-guava/src/ListenableFuture.kt @@ -132,13 +132,19 @@ public fun ListenableFuture.asDeferred(): Deferred { val deferred = CompletableDeferred() Futures.addCallback(this, object : FutureCallback { override fun onSuccess(result: T) { - runCatching { deferred.complete(result) } - .onFailure { handleCoroutineException(EmptyCoroutineContext, it) } + try { + deferred.complete(result) + } catch (e: Exception) { + handleCoroutineException(EmptyCoroutineContext, e) + } } override fun onFailure(t: Throwable) { - runCatching { deferred.completeExceptionally(t) } - .onFailure { handleCoroutineException(EmptyCoroutineContext, it) } + try { + deferred.completeExceptionally(t) + } catch (e: Exception) { + handleCoroutineException(EmptyCoroutineContext, e) + } } }, MoreExecutors.directExecutor()) @@ -268,6 +274,8 @@ private class ToContinuation( // Future. Anything else showing up here indicates a very fundamental bug in a // Future implementation. continuation.resumeWithException(e.nonNullCause()) + } catch (e: CancellationException) { + continuation.cancel(e) } } }