Fix usingCancellable with null ret value

This commit is contained in:
tarsin committed 2023-05-29 20:04:15 +08:00
1 parent 6e96571cc8
commit d464d00067
2 files changed
+5 -4

No files matched your search

@@ -116,7 +116,7 @@ private fun rethrowExactly(code: Int, headers: Headers, body: String, e: Throwab
throw e
}
private suspend inline fun <T> Request.executeAndParsingWith(block: String.() -> T): T {
private suspend inline fun <T> Request.executeAndParsingWith(crossinline block: String.() -> T): T {
Log.d(TAG, url.toString())
return execute {
val body = body.string()
@@ -79,10 +79,11 @@ suspend inline fun <R> Call.usingCancellable(crossinline block: Response.() -> R
r.exceptionOrNull()?.let {
Log.e(TAG_CALL, "Reading response of call$call failed!")
cont.resumeWithException(it)
}
r.getOrNull()?.let {
} ?: run {
Log.d(TAG_CALL, "Reading response of call$call succeed!")
cont.resume(it)
// R maybe null
@Suppress("UNCHECKED_CAST")
cont.resume(r.getOrNull() as R)
}
} else if (isCanceled() && cont.isActive) {
Log.e(TAG_CALL, "call$call cancelled but coroutine is Active!")