mirror of
https://github.com/square/okhttp.git
synced 2025-11-21 18:40:53 +03:00
* Don't leak response bodies in executeAsync Also make callers opt in to an unstable coroutines API. If the resource cleanup coroutines API changes, we'll have to change this API. Remove the OkHttp experimental API. This is a good enough API as far as OkHttp is concerned. * Spotless
OkHttp Coroutines
Support for Kotlin clients using coroutines.
val call = client.newCall(request)
call.executeAsync().use { response ->
withContext(Dispatchers.IO) {
println(response.body?.string())
}
}
This is implemented using suspendCancellableCoroutine
but uses the standard Dispatcher in OkHttp. This means
that by default Kotlin's Dispatchers are not used.
Cancellation if implemented sensibly in both directions. Cancelling a coroutine scope, will cancel the call. Cancelling a call, will throw a CancellationException but not cancel the scope if caught.