elizarov
03/28/2017, 8:45 PMListenableFuture
interface and even provides toCompletableFuture
method, so you can just add a dependency on kotlinx-coroutines-jdk8
module of kotlinx.coroutines
project and define:
suspend fun <V> ListenableFuture<V>.await(): V =
toCompletableFuture().await()
With this suspending function in hand, using this async http library from a coroutine is straightforward, for example:
fun main(args: Array<String>) = runBlocking<Unit> {
val asyncHttpClient = DefaultAsyncHttpClient()
val response = asyncHttpClient.prepareGet("<http://www.example.com/>").execute().await()
println(response.statusCode)
}