55package kotlinx.coroutines.guava
66
77import com.google.common.util.concurrent.*
8- import com.google.common.util.concurrent.internal.InternalFutureFailureAccess
9- import com.google.common.util.concurrent.internal.InternalFutures
8+ import com.google.common.util.concurrent.internal.*
109import kotlinx.coroutines.*
1110import java.util.concurrent.*
1211import java.util.concurrent.CancellationException
@@ -138,10 +137,10 @@ public fun <T> ListenableFuture<T>.asDeferred(): Deferred<T> {
138137 // Finally, if this isn't done yet, attach a Listener that will complete the Deferred.
139138 val deferred = CompletableDeferred <T >()
140139 Futures .addCallback(this , object : FutureCallback <T > {
141- override fun onSuccess (result : T ? ) {
140+ override fun onSuccess (result : T ) {
142141 // Here we work with flexible types, so we unchecked cast to trick the type system
143142 @Suppress(" UNCHECKED_CAST" )
144- runCatching { deferred.complete(result as T ) }
143+ runCatching { deferred.complete(result) }
145144 .onFailure { handleCoroutineException(EmptyCoroutineContext , it) }
146145 }
147146
@@ -225,7 +224,7 @@ public fun <T> Deferred<T>.asListenableFuture(): ListenableFuture<T> {
225224 *
226225 * This suspend function is cancellable.
227226 *
228- * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function
227+ * If the [Job] of the current coroutine is cancelled while this suspending function is waiting, this function
229228 * stops waiting for the future and immediately resumes with [CancellationException][kotlinx.coroutines.CancellationException].
230229 *
231230 * This method is intended to be used with one-shot Futures, so on coroutine cancellation, the Future is cancelled as well.
@@ -247,8 +246,7 @@ public suspend fun <T> ListenableFuture<T>.await(): T {
247246 return suspendCancellableCoroutine { cont: CancellableContinuation <T > ->
248247 addListener(
249248 ToContinuation (this , cont),
250- MoreExecutors .directExecutor()
251- )
249+ MoreExecutors .directExecutor())
252250 cont.invokeOnCancellation {
253251 cancel(false )
254252 }
@@ -265,7 +263,7 @@ public suspend fun <T> ListenableFuture<T>.await(): T {
265263private class ToContinuation <T >(
266264 val futureToObserve : ListenableFuture <T >,
267265 val continuation : CancellableContinuation <T >
268- ) : Runnable {
266+ ): Runnable {
269267 override fun run () {
270268 if (futureToObserve.isCancelled) {
271269 continuation.cancel()
@@ -346,7 +344,7 @@ private class ListenableFutureCoroutine<T>(
346344 * could probably be compressed into one subclass of [AbstractFuture] to save an allocation, at the
347345 * cost of the implementation's readability.
348346 */
349- private class JobListenableFuture <T >(private val jobToCancel : Job ) : ListenableFuture<T> {
347+ private class JobListenableFuture <T >(private val jobToCancel : Job ): ListenableFuture<T> {
350348 /* *
351349 * Serves as a state machine for [Future] cancellation.
352350 *
@@ -356,7 +354,7 @@ private class JobListenableFuture<T>(private val jobToCancel: Job) : ListenableF
356354 *
357355 * To preserve Coroutine's [CancellationException], this future points to either `T` or [Cancelled].
358356 */
359- private val auxFuture = SettableFuture .create<Any >()
357+ private val auxFuture = SettableFuture .create<Any ? >()
360358
361359 /* *
362360 * `true` if [auxFuture.get][ListenableFuture.get] throws [ExecutionException].
@@ -441,7 +439,7 @@ private class JobListenableFuture<T>(private val jobToCancel: Job) : ListenableF
441439 }
442440
443441 /* * See [get()]. */
444- private fun getInternal (result : Any ): T = if (result is Cancelled ) {
442+ private fun getInternal (result : Any? ): T = if (result is Cancelled ) {
445443 throw CancellationException ().initCause(result.exception)
446444 } else {
447445 // We know that `auxFuture` can contain either `T` or `Cancelled`.
0 commit comments