Use coroutines for updater

This commit is contained in:
arkon
2020-02-09 22:24:56 -05:00
parent 340829bb71
commit 6a95ff56df
9 changed files with 67 additions and 81 deletions
@@ -48,11 +48,11 @@ fun Call.asObservable(): Observable<Response> {
}
// Based on https://github.com/gildor/kotlin-coroutines-okhttp
suspend fun Call.await(): Response {
suspend fun Call.await(assertSuccess: Boolean = false): Response {
return suspendCancellableCoroutine { continuation ->
enqueue(object : Callback {
override fun onResponse(call: Call, response: Response) {
if (!response.isSuccessful) {
if (assertSuccess && !response.isSuccessful) {
continuation.resumeWithException(Exception("HTTP error ${response.code}"))
return
}