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

viniciuslrangel

10/21/2018, 10:07 PM
Hi, how should I "await" for a standard Java Future inside a suspending function?
e

elizarov

10/21/2018, 10:15 PM
Using
.await()
assuming your future is in fact a CompletableFuture.
v

viniciuslrangel

10/21/2018, 10:22 PM
I'm using ApiFuture from Google API, which is a standard java.util.concurrent.Future with a addListener method. There is some utility in coroutines to use this addListener and avoid "callback hell"?
e

elizarov

10/22/2018, 1:04 AM
If it implements Guava ListenableFuture then you can use ready implementation of
.await()
from
kotlinx-coroutines-guava
module, if not, then you can copy-and-paste await extension from its source here https://github.com/Kotlin/kotlinx.coroutines/blob/master/integration/kotlinx-coroutines-guava/src/ListenableFuture.kt
v

viniciuslrangel

10/22/2018, 1:27 AM
Sure, thanks
46 Views