<@U0BRK9HC5> you've done the retrofit couroutine l...
# coroutines
k
@gildor you've done the retrofit couroutine library. would you consider making one for okhttp?
g
yeah, I want to start work. But to be honest I have not so many practical use cases where coroutines would be useful for Okhttp
k
I thnik it's only
Call.await
. It's virtually identical to retrofit's
Call
g
Okay, maybe I’ll publish something on this weekend. If you have some thoughts about coroutines for okhttp, be free to message me
👍 1
k
👍
u
I've used this in our project:
Copy code
suspend fun Call.await(): Response = suspendCancellableCoroutine { cont ->
    enqueue(object : Callback {
        override fun onResponse(call: Call, response: Response) {
            cont.resume(response)
        }

        override fun onFailure(call: Call, e: IOException) {
            if (e is InterruptedIOException || cont.isCancelled) return
            cont.resumeWithException(e)
        }
    })
    cont.invokeOnCompletion { if (cont.isCancelled) cancel() }
}