kirillrakhman
04/26/2017, 7:53 AMgildor
04/26/2017, 8:01 AMkirillrakhman
04/26/2017, 8:02 AMCall.await
. It's virtually identical to retrofit's Call
gildor
04/26/2017, 8:06 AMkirillrakhman
04/26/2017, 8:07 AMuhe
04/26/2017, 1:05 PMsuspend 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() }
}