elizarov
11/07/2017, 4:45 PMfrogman544
11/08/2017, 8:08 AMelizarov
11/08/2017, 8:41 AMfrogman544
11/08/2017, 9:55 AMelizarov
11/08/2017, 11:16 AMCall.awaitfrogman544
11/08/2017, 12:37 PMsuspend fun <T> Call<T>.awaitResult(retries: Int = 2): Result<T> {
return suspendCancellableCoroutine { continuation ->
enqueue(object : Callback<T> {
override fun onResponse(call: Call<T>?, response: Response<T>) {
continuation.resume(
if (response.isSuccessful) {
Result.Ok(response.body(), response.raw())
} else {
Result.Error(HttpError(response), response.raw(), call)
}
)
}
override fun onFailure(call: Call<T>, t: Throwable) {
continuation.resume(Result.Exception(t))
}
})
}
}frogman544
11/08/2017, 12:40 PMretry { actualCall.awaitResult }elizarov
11/08/2017, 1:48 PMawaitResult implementation never resumes with exception, so it is no surprise that try { … } catch inside retry is not doing anythingelizarov
11/08/2017, 1:50 PMawait that throws exceptions on error.
2. Or implement a version of retry that is specifically tailored to Resut<T> can can make decisions based on itfrogman544
11/09/2017, 8:02 AM