Stay organized with collections
Save and categorize content based on your preferences.
Interfaces
Classes
Objects
SuspendToFutureAdapter |
A utility for launching suspending calls scoped and managed by a returned ListenableFuture , used for adapting Kotlin suspending APIs to be callable from the Java programming language.
|
Extension functions summary
Extension functions
suspend fun <T : Any?> ListenableFuture<T>.await(): T
Awaits completion of this
ListenableFuture
without blocking a thread.
This suspend function is cancellable.
If the kotlinx.coroutines.Job
of the current coroutine is cancelled or completed while this suspending function is waiting, this function stops waiting for the future and immediately resumes with CancellationException
.
This method is intended to be used with one-shot Futures, so on coroutine cancellation, the Future is cancelled as well. If cancelling the given future is undesired, use kotlinx.coroutines.NonCancellable
.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-05-15 UTC.
[null,null,["Last updated 2025-05-15 UTC."],[],[],null,["# androidx.concurrent.futures\n===========================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/androidx/concurrent/futures/package-summary \"View this page in Java\")\n\nInterfaces\n----------\n\n|--------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [CallbackToFutureAdapter.Resolver](/reference/kotlin/androidx/concurrent/futures/CallbackToFutureAdapter.Resolver) | This interface should be implemented by the object passed into [getFuture](/reference/kotlin/androidx/concurrent/futures/CallbackToFutureAdapter#getFuture(androidx.concurrent.futures.CallbackToFutureAdapter.Resolver\u003cT\u003e)). |\n\nClasses\n-------\n\n|----------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [CallbackToFutureAdapter](/reference/kotlin/androidx/concurrent/futures/CallbackToFutureAdapter) | A utility useful for adapting interfaces that take callbacks into interfaces that return . |\n| [CallbackToFutureAdapter.Completer](/reference/kotlin/androidx/concurrent/futures/CallbackToFutureAdapter.Completer) | Used to complete the future returned by [getFuture](/reference/kotlin/androidx/concurrent/futures/CallbackToFutureAdapter#getFuture(androidx.concurrent.futures.CallbackToFutureAdapter.Resolver\u003cT\u003e)) |\n\nObjects\n-------\n\n|------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [SuspendToFutureAdapter](/reference/kotlin/androidx/concurrent/futures/SuspendToFutureAdapter) | A utility for launching suspending calls scoped and managed by a returned [ListenableFuture](https://guava.dev/releases/18.0/api/docs/com/google/common/util/concurrent/ListenableFuture.html), used for adapting Kotlin suspending APIs to be callable from the Java programming language. |\n\nExtension functions summary\n---------------------------\n\n|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `suspend T` | `\u003cT : `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?\u003e `[ListenableFuture](https://guava.dev/releases/18.0/api/docs/com/google/common/util/concurrent/ListenableFuture.html)`\u003cT\u003e.`[await](/reference/kotlin/androidx/concurrent/futures/package-summary#(com.google.common.util.concurrent.ListenableFuture).await())`()` Awaits completion of `this` [ListenableFuture](https://guava.dev/releases/18.0/api/docs/com/google/common/util/concurrent/ListenableFuture.html) without blocking a thread. |\n\nExtension functions\n-------------------\n\n### await\n\nArtifact: [androidx.concurrent:concurrent-futures-ktx](/jetpack/androidx/releases/concurrent) \n[View Source](https://cs.android.com/search?q=file:androidx/concurrent/futures/ListenableFuture.kt+function:await) \n\n```\nsuspend fun \u003cT : Any?\u003e ListenableFuture\u003cT\u003e.await(): T\n```\n\nAwaits completion of `this` [ListenableFuture](https://guava.dev/releases/18.0/api/docs/com/google/common/util/concurrent/ListenableFuture.html) without blocking a thread.\n\nThis suspend function is cancellable.\n\nIf the [kotlinx.coroutines.Job](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html) of the current coroutine is cancelled or completed while this suspending function is waiting, this function stops waiting for the future and immediately resumes with [CancellationException](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/index.html).\n\nThis method is intended to be used with one-shot Futures, so on coroutine cancellation, the Future is cancelled as well. If cancelling the given future is undesired, use [kotlinx.coroutines.NonCancellable](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-non-cancellable/index.html)."]]